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.
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new OrdinalEncoder(opts?: object): OrdinalEncoder;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.categories? | "auto" | Categories (unique values) per feature: Default Value 'auto' |
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 . Default Value 'error' |
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
Defined in: generated/preprocessing/OrdinalEncoder.ts:25 (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:361 (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:411 (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:386 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/preprocessing/OrdinalEncoder.ts:59 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/preprocessing/OrdinalEncoder.ts:63 (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:118 (opens in a new tab)
fit()
Fit the OrdinalEncoder to X.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | 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:135 (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
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Input samples. |
opts.fit_params? | any | Additional fit parameters. |
opts.y? | ArrayLike | Target values (undefined for unsupervised transformations). |
Returns
Promise
<any
[]>
Defined in: generated/preprocessing/OrdinalEncoder.ts:175 (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
Name | Type | Description |
---|---|---|
opts | object | - |
opts.input_features? | any | Input features. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/OrdinalEncoder.ts:222 (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
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/preprocessing/OrdinalEncoder.ts:72 (opens in a new tab)
inverse_transform()
Convert the data back to the original representation.
Signature
inverse_transform(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | The transformed data. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/preprocessing/OrdinalEncoder.ts:258 (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
Name | Type | Description |
---|---|---|
opts | object | - |
opts.transform? | "default" | "pandas" | Configure output of transform and fit\_transform . |
Returns
Promise
<any
>
Defined in: generated/preprocessing/OrdinalEncoder.ts:295 (opens in a new tab)
transform()
Transform X to ordinal codes.
Signature
transform(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | The data to encode. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/preprocessing/OrdinalEncoder.ts:328 (opens in a new tab)