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.
Constructors
new OrdinalEncoder()
new OrdinalEncoder(
opts
?):OrdinalEncoder
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.categories ? | "auto" | Categories (unique values) per feature: |
opts.dtype ? | any | Desired dtype of output. |
opts.encoded_missing_value ? | number | Encoded 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 ? | number | Specifies 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 ? | number | Specifies the minimum frequency below which a category will be considered infrequent. |
opts.unknown_value ? | number | 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 . If set to np.nan, the dtype parameter must be a float dtype. |
Returns OrdinalEncoder
Defined in generated/preprocessing/OrdinalEncoder.ts:25
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/preprocessing/OrdinalEncoder.ts:23 |
_isInitialized | boolean | false | generated/preprocessing/OrdinalEncoder.ts:22 |
_py | PythonBridge | undefined | generated/preprocessing/OrdinalEncoder.ts:21 |
id | string | undefined | generated/preprocessing/OrdinalEncoder.ts:18 |
opts | any | undefined | generated/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
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The data to determine the categories of each feature. |
opts.y ? | any | Ignored. 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Additional fit parameters. |
opts.X ? | ArrayLike [] | Input samples. |
opts.y ? | ArrayLike | Target 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.input_features ? | any | Input 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A 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
Parameter | Type |
---|---|
py | PythonBridge |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The data to encode. |
Returns Promise
<ArrayLike
[]>