snowflake.ml.modeling.preprocessing.OrdinalEncoder

class snowflake.ml.modeling.preprocessing.OrdinalEncoder(*, categories: Union[str, Dict[str, Union[ndarray[Any, dtype[int64]], ndarray[Any, dtype[float64]], ndarray[Any, dtype[str_]], ndarray[Any, dtype[bool_]]]]] = 'auto', handle_unknown: str = 'error', unknown_value: Optional[Union[int, float]] = None, encoded_missing_value: Union[int, float] = nan, input_cols: Optional[Union[str, Iterable[str]]] = None, output_cols: Optional[Union[str, Iterable[str]]] = None, passthrough_cols: Optional[Union[str, Iterable[str]]] = None, drop_input_cols: Optional[bool] = False)

Bases: BaseTransformer

Encodes categorical features as an integer array.

In other words, each category (i.e., distinct numeric or string value) is assigned an integer value, starting with zero.

For more details on what this transformer does, see sklearn.preprocessing.OrdinalEncoder.

Args:
categories: Union[str, Dict[str, type_utils.LiteralNDArrayType]], default=”auto”

The string ‘auto’ (the default) causes the categories to be extracted from the input columns. To specify the categories yourself, pass a dictionary mapping the column name to an ndarray containing the categories.

handle_unknown: str, default=”error”

Specifies how unknown categories are handled during transformation. Applicable only if categories is not ‘auto’. Valid values are:

  • ‘error’: Raise an error if an unknown category is present during transform (default).

  • ‘use_encoded_value’: When an unknown category is encountered during transform, the specified

    encoded_missing_value (below) is used.

unknown_value: Optional[Union[int, float]], default=None

When the parameter handle_unknown is set to ‘use_encoded_value’, this parameter is required and will set the encoded value of unknown categories. It has to be distinct from the values used to encode any of the categories in fit.

encoded_missing_value: Union[int, float], default=np.nan

The value to be used to encode unknown categories.

input_cols: Optional[Union[str, List[str]]], default=None

The name(s) of one or more columns in a DataFrame containing a feature to be encoded.

output_cols: Optional[Union[str, List[str]]], default=None

The name(s) of one or more columns in a DataFrame in which results will be stored. The number of columns specified must match the number of input columns.

passthrough_cols: Optional[Union[str, List[str]]], default=None

A string or a list of strings indicating column names to be excluded from any operations (such as train, transform, or inference). These specified column(s) will remain untouched throughout the process. This option is helpful in scenarios requiring automatic input_cols inference, but need to avoid using specific columns, like index columns, during training or inference.

drop_input_cols: Optional[bool], default=False

Remove input columns from output if set True. False by default.

Attributes:
categories_ (dict of ndarray): List[type_utils.LiteralNDArrayType]

The categories of each feature determined during fitting. Maps input column names to an array of the detected categories. Attributes are valid only after fit() has been called.

Methods

fit(dataset)

Fit the OrdinalEncoder to dataset.

get_input_cols()

Input columns getter.

get_label_cols()

Label column getter.

get_output_cols()

Output columns getter.

get_params([deep])

Get parameters for this transformer.

get_passthrough_cols()

Passthrough columns getter.

get_sample_weight_col()

Sample weight column getter.

get_sklearn_args([default_sklearn_obj, ...])

Get sklearn keyword arguments.

set_drop_input_cols([drop_input_cols])

set_input_cols(input_cols)

Input columns setter.

set_label_cols(label_cols)

Label column setter.

set_output_cols(output_cols)

Output columns setter.

set_params(**params)

Set the parameters of this transformer.

set_passthrough_cols(passthrough_cols)

Passthrough columns setter.

set_sample_weight_col(sample_weight_col)

Sample weight column setter.

to_lightgbm()

to_sklearn()

to_xgboost()

transform(dataset)

Transform dataset to ordinal codes.