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.

Python Reference

Constructors

new SimpleImputer()

new SimpleImputer(opts?): SimpleImputer

Parameters

ParameterTypeDescription
opts?object-
opts.add_indicator?booleanIf 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?booleanIf 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?stringWhen 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?booleanIf 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 | numberThe 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?stringThe imputation strategy.

Returns SimpleImputer

Defined in generated/impute/SimpleImputer.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/impute/SimpleImputer.ts:23
_isInitializedbooleanfalsegenerated/impute/SimpleImputer.ts:22
_pyPythonBridgeundefinedgenerated/impute/SimpleImputer.ts:21
idstringundefinedgenerated/impute/SimpleImputer.ts:18
optsanyundefinedgenerated/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

ParameterType
pythonBridgePythonBridge

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

ParameterTypeDescription
optsobject-
opts.X?anyInput data, where n_samples is the number of samples and n_features is the number of features.
opts.y?anyNot 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

ParameterTypeDescription
optsobject-
opts.fit_params?anyAdditional fit parameters.
opts.X?ArrayLike[]Input samples.
opts.y?ArrayLikeTarget 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

ParameterTypeDescription
optsobject-
opts.input_features?anyInput 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

ParameterTypeDescription
optsobject-
opts.routing?anyA 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

ParameterType
pyPythonBridge

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

ParameterTypeDescription
optsobject-
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

ParameterTypeDescription
optsobject-
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

ParameterTypeDescription
optsobject-
opts.X?anyThe input data to complete.

Returns Promise<ArrayLike>

Defined in generated/impute/SimpleImputer.ts:360