Skip to content

Latest commit

 

History

History
343 lines (203 loc) · 9.69 KB

KNNImputer.md

File metadata and controls

343 lines (203 loc) · 9.69 KB

KNNImputer

Imputation for completing missing values using k-Nearest Neighbors.

Each sample’s missing values are imputed using the mean value from n\_neighbors nearest neighbors found in the training set. Two samples are close if the features that neither is missing are close.

Read more in the User Guide.

Python Reference

Constructors

constructor()

Signature

new KNNImputer(opts?: object): KNNImputer;

Parameters

Name Type Description
opts? object -
opts.add_indicator? boolean If true, a MissingIndicator transform will stack onto the 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? boolean If true, a copy of X will be created. If false, imputation will be done in-place whenever possible. Default Value true
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. Default Value false
opts.metric? "nan_euclidean" Distance metric for searching neighbors. Possible values: Default Value 'nan_euclidean'
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 should be set to np.nan, since pd.NA will be converted to np.nan.
opts.n_neighbors? number Number of neighboring samples to use for imputation. Default Value 5
opts.weights? "uniform" | "distance" Weight function used in prediction. Possible values: Default Value 'uniform'

Returns

KNNImputer

Defined in: generated/impute/KNNImputer.ts:25

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/KNNImputer.ts:136

fit()

Fit the imputer on X.

Signature

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

Parameters

Name 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/KNNImputer.ts:153

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/impute/KNNImputer.ts:193

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/impute/KNNImputer.ts:240

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

Name Type Description
opts object -
opts.routing? any A MetadataRequest encapsulating routing information.

Returns

Promise<any>

Defined in: generated/impute/KNNImputer.ts:278

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/impute/KNNImputer.ts:90

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/impute/KNNImputer.ts:315

transform()

Impute all missing values in X.

Signature

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

Parameters

Name Type Description
opts object -
opts.X? ArrayLike[] The input data to complete.

Returns

Promise<ArrayLike[]>

Defined in: generated/impute/KNNImputer.ts:348

Properties

_isDisposed

boolean = false

Defined in: generated/impute/KNNImputer.ts:23

_isInitialized

boolean = false

Defined in: generated/impute/KNNImputer.ts:22

_py

PythonBridge

Defined in: generated/impute/KNNImputer.ts:21

id

string

Defined in: generated/impute/KNNImputer.ts:18

opts

any

Defined in: generated/impute/KNNImputer.ts:19

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/KNNImputer.ts:429

indicator_

Indicator used to add binary indicators for missing values. undefined if add_indicator is false.

Signature

indicator_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/impute/KNNImputer.ts:381

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/impute/KNNImputer.ts:404

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/impute/KNNImputer.ts:77

Signature

py(pythonBridge: PythonBridge): void;

Parameters

Name Type
pythonBridge PythonBridge

Returns

void

Defined in: generated/impute/KNNImputer.ts:81