DocumentationClassesOrdinalEncoder

Class: OrdinalEncoder

Encode categorical features as an integer array.

The input to this transformer should be an array-like of integers or strings, denoting the values taken on by categorical (discrete) features. The features are converted to ordinal integers. This results in a single column of integers (0 to n_categories - 1) per feature.

Read more in the User Guide. For a comparison of different encoders, refer to: Comparing Target Encoder with Other Encoders.

Python Reference

Constructors

new OrdinalEncoder()

new OrdinalEncoder(opts?): OrdinalEncoder

Parameters

ParameterTypeDescription
opts?object-
opts.categories?"auto"Categories (unique values) per feature:
opts.dtype?anyDesired dtype of output.
opts.encoded_missing_value?numberEncoded value of missing categories. If set to np.nan, then the dtype parameter must be a float dtype.
opts.handle_unknown?"error" | "use_encoded_value"When set to ‘error’ an error will be raised in case an unknown categorical feature is present during transform. When set to ‘use_encoded_value’, the encoded value of unknown categories will be set to the value given for the parameter unknown_value. In inverse_transform, an unknown category will be denoted as undefined.
opts.max_categories?numberSpecifies an upper limit to the number of output categories for each input feature when considering infrequent categories. If there are infrequent categories, max_categories includes the category representing the infrequent categories along with the frequent categories. If undefined, there is no limit to the number of output features. max_categories do not take into account missing or unknown categories. Setting unknown_value or encoded_missing_value to an integer will increase the number of unique integer codes by one each. This can result in up to max_categories + 2 integer codes.
opts.min_frequency?numberSpecifies the minimum frequency below which a category will be considered infrequent.
opts.unknown_value?numberWhen 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. If set to np.nan, the dtype parameter must be a float dtype.

Returns OrdinalEncoder

Defined in generated/preprocessing/OrdinalEncoder.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/preprocessing/OrdinalEncoder.ts:23
_isInitializedbooleanfalsegenerated/preprocessing/OrdinalEncoder.ts:22
_pyPythonBridgeundefinedgenerated/preprocessing/OrdinalEncoder.ts:21
idstringundefinedgenerated/preprocessing/OrdinalEncoder.ts:18
optsanyundefinedgenerated/preprocessing/OrdinalEncoder.ts:19

Accessors

categories_

Get Signature

get categories_(): Promise<any>

The categories of each feature determined during fit (in order of the features in X and corresponding with the output of transform). This does not include categories that weren’t seen during fit.

Returns Promise<any>

Defined in generated/preprocessing/OrdinalEncoder.ts:391


feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/preprocessing/OrdinalEncoder.ts:441


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/preprocessing/OrdinalEncoder.ts:416


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/preprocessing/OrdinalEncoder.ts:71

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/preprocessing/OrdinalEncoder.ts:123


fit()

fit(opts): Promise<any>

Fit the OrdinalEncoder to X.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]The data to determine the categories of each feature.
opts.y?anyIgnored. This parameter exists only for compatibility with Pipeline.

Returns Promise<any>

Defined in generated/preprocessing/OrdinalEncoder.ts:140


fit_transform()

fit_transform(opts): Promise<any[]>

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters

ParameterTypeDescription
optsobject-
opts.fit_params?anyAdditional fit parameters.
opts.X?ArrayLike[]Input samples.
opts.y?ArrayLikeTarget values (undefined for unsupervised transformations).

Returns Promise<any[]>

Defined in generated/preprocessing/OrdinalEncoder.ts:179


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

Get output feature names for transformation.

Parameters

ParameterTypeDescription
optsobject-
opts.input_features?anyInput features.

Returns Promise<any>

Defined in generated/preprocessing/OrdinalEncoder.ts:221


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/preprocessing/OrdinalEncoder.ts:257


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/preprocessing/OrdinalEncoder.ts:84


inverse_transform()

inverse_transform(opts): Promise<ArrayLike[]>

Convert the data back to the original representation.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]The transformed data.

Returns Promise<ArrayLike[]>

Defined in generated/preprocessing/OrdinalEncoder.ts:291


set_output()

set_output(opts): Promise<any>

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters

ParameterTypeDescription
optsobject-
opts.transform?"default" | "pandas" | "polars"Configure output of transform and fit_transform.

Returns Promise<any>

Defined in generated/preprocessing/OrdinalEncoder.ts:327


transform()

transform(opts): Promise<ArrayLike[]>

Transform X to ordinal codes.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]The data to encode.

Returns Promise<ArrayLike[]>

Defined in generated/preprocessing/OrdinalEncoder.ts:359