Documentation
Classes
OrdinalEncoder

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 (opens in a new tab)

Constructors

constructor()

Signature

new OrdinalEncoder(opts?: object): OrdinalEncoder;

Parameters

NameTypeDescription
opts?object-
opts.categories?"auto"Categories (unique values) per feature: Default Value 'auto'
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. Default Value 'error'
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 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

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

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/preprocessing/OrdinalEncoder.ts:132 (opens in a new tab)

fit()

Fit the OrdinalEncoder to X.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
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:149 (opens in a new tab)

fit_transform()

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit\_params and returns a transformed version of X.

Signature

fit_transform(opts: object): Promise<any[]>;

Parameters

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

Returns

Promise<any[]>

Defined in: generated/preprocessing/OrdinalEncoder.ts:189 (opens in a new tab)

get_feature_names_out()

Get output feature names for transformation.

Signature

get_feature_names_out(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.input_features?anyInput features.

Returns

Promise<any>

Defined in: generated/preprocessing/OrdinalEncoder.ts:236 (opens in a new tab)

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Signature

get_metadata_routing(opts: object): Promise<any>;

Parameters

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

Returns

Promise<any>

Defined in: generated/preprocessing/OrdinalEncoder.ts:274 (opens in a new tab)

init()

Initializes the underlying Python resources.

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

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/preprocessing/OrdinalEncoder.ts:84 (opens in a new tab)

inverse_transform()

Convert the data back to the original representation.

Signature

inverse_transform(opts: object): Promise<ArrayLike[]>;

Parameters

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

Returns

Promise<ArrayLike[]>

Defined in: generated/preprocessing/OrdinalEncoder.ts:309 (opens in a new tab)

set_output()

Set output container.

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

Signature

set_output(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.transform?"default" | "pandas"Configure output of transform and fit\_transform.

Returns

Promise<any>

Defined in: generated/preprocessing/OrdinalEncoder.ts:346 (opens in a new tab)

transform()

Transform X to ordinal codes.

Signature

transform(opts: object): Promise<ArrayLike[]>;

Parameters

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

Returns

Promise<ArrayLike[]>

Defined in: generated/preprocessing/OrdinalEncoder.ts:379 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/preprocessing/OrdinalEncoder.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/preprocessing/OrdinalEncoder.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/preprocessing/OrdinalEncoder.ts:21 (opens in a new tab)

id

string

Defined in: generated/preprocessing/OrdinalEncoder.ts:18 (opens in a new tab)

opts

any

Defined in: generated/preprocessing/OrdinalEncoder.ts:19 (opens in a new tab)

Accessors

categories_

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.

Signature

categories_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/preprocessing/OrdinalEncoder.ts:412 (opens in a new tab)

feature_names_in_

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

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/preprocessing/OrdinalEncoder.ts:462 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/preprocessing/OrdinalEncoder.ts:437 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/preprocessing/OrdinalEncoder.ts:71 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/preprocessing/OrdinalEncoder.ts:75 (opens in a new tab)