Class: SimpleImputer
Univariate imputer for completing missing values with simple strategies.
Replace missing values using a descriptive statistic (e.g. mean, median, or most frequent) along each column, or using a constant value.
Read more in the User Guide.
Constructors
new SimpleImputer()
new SimpleImputer(
opts
?):SimpleImputer
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.add_indicator ? | boolean | If true , a MissingIndicator transform will stack onto output of the imputer’s transform. This allows a predictive estimator to account for missingness despite imputation. If a feature has no missing values at fit/train time, the feature won’t appear on the missing indicator even if there are missing values at transform/test time. |
opts.copy ? | boolean | If true , a copy of X will be created. If false , imputation will be done in-place whenever possible. Note that, in the following cases, a new copy will always be made, even if copy=False : |
opts.fill_value ? | string | When strategy == “constant”, fill_value is used to replace all occurrences of missing_values. For string or object data types, fill_value must be a string. If undefined , fill_value will be 0 when imputing numerical data and “missing_value” for strings or object data types. |
opts.keep_empty_features ? | boolean | If true , features that consist exclusively of missing values when fit is called are returned in results when transform is called. The imputed value is always 0 except when strategy="constant" in which case fill_value will be used instead. |
opts.missing_values ? | string | number | The placeholder for the missing values. All occurrences of missing_values will be imputed. For pandas’ dataframes with nullable integer dtypes with missing values, missing_values can be set to either np.nan or pd.NA . |
opts.strategy ? | string | The imputation strategy. |
Returns SimpleImputer
Defined in generated/impute/SimpleImputer.ts:25
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/impute/SimpleImputer.ts:23 |
_isInitialized | boolean | false | generated/impute/SimpleImputer.ts:22 |
_py | PythonBridge | undefined | generated/impute/SimpleImputer.ts:21 |
id | string | undefined | generated/impute/SimpleImputer.ts:18 |
opts | any | undefined | generated/impute/SimpleImputer.ts:19 |
Accessors
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/impute/SimpleImputer.ts:467
indicator_
Get Signature
get indicator_():
Promise
<any
>
Indicator used to add binary indicators for missing values. undefined
if add_indicator=False
.
Returns Promise
<any
>
Defined in generated/impute/SimpleImputer.ts:417
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/impute/SimpleImputer.ts:442
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/impute/SimpleImputer.ts:68
statistics_
Get Signature
get statistics_():
Promise
<any
[]>
The imputation fill value for each feature. Computing statistics can result in np.nan
values. During transform
, features corresponding to np.nan
statistics will be discarded.
Returns Promise
<any
[]>
Defined in generated/impute/SimpleImputer.ts:392
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/impute/SimpleImputer.ts:120
fit()
fit(
opts
):Promise
<any
>
Fit the imputer on X
.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any | Input data, where n_samples is the number of samples and n_features is the number of features. |
opts.y ? | any | Not used, present here for API consistency by convention. |
Returns Promise
<any
>
Defined in generated/impute/SimpleImputer.ts:137
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/impute/SimpleImputer.ts:176
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/impute/SimpleImputer.ts:218
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/impute/SimpleImputer.ts:254
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/impute/SimpleImputer.ts:81
inverse_transform()
inverse_transform(
opts
):Promise
<ArrayLike
[]>
Convert the data back to the original representation.
Inverts the transform
operation performed on an array. This operation can only be performed after SimpleImputer
is instantiated with add_indicator=True
.
Note that inverse_transform
can only invert the transform in features that have binary indicators for missing values. If a feature has no missing values at fit
time, the feature won’t have a binary indicator, and the imputation done at transform
time won’t be inverted.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The imputed data to be reverted to original data. It has to be an augmented array of imputed data and the missing indicator mask. |
Returns Promise
<ArrayLike
[]>
Defined in generated/impute/SimpleImputer.ts:292
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/impute/SimpleImputer.ts:328
transform()
transform(
opts
):Promise
<ArrayLike
>
Impute all missing values in X
.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any | The input data to complete. |
Returns Promise
<ArrayLike
>
Defined in generated/impute/SimpleImputer.ts:360