Target Encoder for regression and classification targets.
Each category is encoded based on a shrunk estimate of the average target values for observations belonging to the category. The encoding scheme mixes the global target mean with the target mean conditioned on the value of the category. [MIC]
TargetEncoder
considers missing values, such as np.nan
or undefined
, as another category and encodes them like any other category. Categories that are not seen during fit
are encoded with the target mean, i.e. target\_mean\_
.
For a demo on the importance of the TargetEncoder
internal cross-fitting, see ref:sphx\_glr\_auto\_examples\_preprocessing\_plot\_target\_encoder\_cross\_val.py
. For a comparison of different encoders, refer to Comparing Target Encoder with Other Encoders. Read more in the User Guide.
new TargetEncoder(opts?: object): TargetEncoder;
Name | Type | Description |
---|---|---|
opts? |
object |
- |
opts.categories? |
"auto" |
Categories (unique values) per feature: Default Value 'auto' |
opts.cv? |
number |
Determines the number of folds in the cross fitting strategy used in fit\_transform . For classification targets, StratifiedKFold is used and for continuous targets, KFold is used. Default Value 5 |
opts.random_state? |
number |
When shuffle is true , random\_state affects the ordering of the indices, which controls the randomness of each fold. Otherwise, this parameter has no effect. Pass an int for reproducible output across multiple function calls. See Glossary. |
opts.shuffle? |
boolean |
Whether to shuffle the data in fit\_transform before splitting into folds. Note that the samples within each split will not be shuffled. Default Value true |
opts.smooth? |
number | "auto" |
The amount of mixing of the target mean conditioned on the value of the category with the global target mean. A larger smooth value will put more weight on the global target mean. If "auto" , then smooth is set to an empirical Bayes estimate. Default Value 'auto' |
opts.target_type? |
"auto" | "binary" | "continuous" |
Type of target. Default Value 'auto' |
Defined in: generated/preprocessing/TargetEncoder.ts:27
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
dispose(): Promise<void>;
Promise
<void
>
Defined in: generated/preprocessing/TargetEncoder.ts:131
Fit the TargetEncoder
to X and y.
fit(opts: object): Promise<any>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.X? |
ArrayLike [] |
The data to determine the categories of each feature. |
opts.y? |
ArrayLike |
The target data used to encode the categories. |
Promise
<any
>
Defined in: generated/preprocessing/TargetEncoder.ts:148
Fit TargetEncoder
and transform X with the target encoding.
fit_transform(opts: object): Promise<ArrayLike[]>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.X? |
ArrayLike [] |
The data to determine the categories of each feature. |
opts.y? |
ArrayLike |
The target data used to encode the categories. |
Promise
<ArrayLike
[]>
Defined in: generated/preprocessing/TargetEncoder.ts:188
Get output feature names for transformation.
get_feature_names_out(opts: object): Promise<any>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.input_features? |
any |
Input features. |
Promise
<any
>
Defined in: generated/preprocessing/TargetEncoder.ts:228
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
get_metadata_routing(opts: object): Promise<any>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.routing? |
any |
A MetadataRequest encapsulating routing information. |
Promise
<any
>
Defined in: generated/preprocessing/TargetEncoder.ts:266
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
init(py: PythonBridge): Promise<void>;
Name | Type |
---|---|
py |
PythonBridge |
Promise
<void
>
Defined in: generated/preprocessing/TargetEncoder.ts:85
Set output container.
See Introducing the set_output API for an example on how to use the API.
set_output(opts: object): Promise<any>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.transform? |
"default" | "pandas" |
Configure output of transform and fit\_transform . |
Promise
<any
>
Defined in: generated/preprocessing/TargetEncoder.ts:303
Transform X with the target encoding.
transform(opts: object): Promise<ArrayLike[]>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.X? |
ArrayLike [] |
The data to determine the categories of each feature. |
Promise
<ArrayLike
[]>
Defined in: generated/preprocessing/TargetEncoder.ts:336
boolean
=false
Defined in: generated/preprocessing/TargetEncoder.ts:25
boolean
=false
Defined in: generated/preprocessing/TargetEncoder.ts:24
PythonBridge
Defined in: generated/preprocessing/TargetEncoder.ts:23
string
Defined in: generated/preprocessing/TargetEncoder.ts:20
any
Defined in: generated/preprocessing/TargetEncoder.ts:21
The categories of each feature determined during fitting or specified in categories
(in order of the features in X
and corresponding with the output of transform
).
categories_(): Promise<any>;
Promise
<any
>
Defined in: generated/preprocessing/TargetEncoder.ts:394
Encodings learnt on all of X
. For feature i
, encodings\_\[i\]
are the encodings matching the categories listed in categories\_\[i\]
.
encodings_(): Promise<any>;
Promise
<any
>
Defined in: generated/preprocessing/TargetEncoder.ts:369
Names of features seen during fit. Defined only when X
has feature names that are all strings.
feature_names_in_(): Promise<ArrayLike>;
Promise
<ArrayLike
>
Defined in: generated/preprocessing/TargetEncoder.ts:494
Number of features seen during fit.
n_features_in_(): Promise<number>;
Promise
<number
>
Defined in: generated/preprocessing/TargetEncoder.ts:469
py(): PythonBridge;
PythonBridge
Defined in: generated/preprocessing/TargetEncoder.ts:72
py(pythonBridge: PythonBridge): void;
Name | Type |
---|---|
pythonBridge |
PythonBridge |
void
Defined in: generated/preprocessing/TargetEncoder.ts:76
The overall mean of the target. This value is only used in transform
to encode categories.
target_mean_(): Promise<number>;
Promise
<number
>
Defined in: generated/preprocessing/TargetEncoder.ts:444
Type of target.
target_type_(): Promise<string>;
Promise
<string
>
Defined in: generated/preprocessing/TargetEncoder.ts:419