You are viewing documentation about an older version (1.0.9). View latest version

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, 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: 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: 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: 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: The value to be used to encode unknown categories. input_cols: The name(s) of one or more columns in a DataFrame containing a feature to be encoded. output_cols: 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.

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

Attributes:
categories_ (dict of ndarray): 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.

transform(dataset)

Transform dataset to ordinal codes.