Documentation
Classes
SimpleImputer

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 (opens in a new tab)

Constructors

constructor()

Signature

new SimpleImputer(opts?: object): SimpleImputer;

Parameters

NameTypeDescription
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. Default Value false
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: Default Value true
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. Default Value false
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. Default Value 'mean'

Returns

SimpleImputer

Defined in: generated/impute/SimpleImputer.ts:25 (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/impute/SimpleImputer.ts:125 (opens in a new tab)

fit()

Fit the imputer on X.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
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:142 (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

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Input samples.
opts.fit_params?anyAdditional fit parameters.
opts.y?ArrayLikeTarget values (undefined for unsupervised transformations).

Returns

Promise<any[]>

Defined in: generated/impute/SimpleImputer.ts:182 (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

NameTypeDescription
optsobject-
opts.input_features?anyInput features.

Returns

Promise<any>

Defined in: generated/impute/SimpleImputer.ts:229 (opens in a new tab)

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Signature

get_metadata_routing(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns

Promise<any>

Defined in: generated/impute/SimpleImputer.ts:267 (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

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/impute/SimpleImputer.ts:81 (opens in a new tab)

inverse_transform()

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.

Signature

inverse_transform(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
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:306 (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

NameTypeDescription
optsobject-
opts.transform?"default" | "pandas"Configure output of transform and fit\_transform.

Returns

Promise<any>

Defined in: generated/impute/SimpleImputer.ts:343 (opens in a new tab)

transform()

Impute all missing values in X.

Signature

transform(opts: object): Promise<ArrayLike>;

Parameters

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

Returns

Promise<ArrayLike>

Defined in: generated/impute/SimpleImputer.ts:376 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/impute/SimpleImputer.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/impute/SimpleImputer.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/impute/SimpleImputer.ts:21 (opens in a new tab)

id

string

Defined in: generated/impute/SimpleImputer.ts:18 (opens in a new tab)

opts

any

Defined in: generated/impute/SimpleImputer.ts:19 (opens in a new tab)

Accessors

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/impute/SimpleImputer.ts:484 (opens in a new tab)

indicator_

Indicator used to add binary indicators for missing values. undefined if add\_indicator=False.

Signature

indicator_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/impute/SimpleImputer.ts:434 (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/impute/SimpleImputer.ts:459 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/impute/SimpleImputer.ts:68 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/impute/SimpleImputer.ts:72 (opens in a new tab)

statistics_

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.

Signature

statistics_(): Promise<any[]>;

Returns

Promise<any[]>

Defined in: generated/impute/SimpleImputer.ts:409 (opens in a new tab)