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.
new KNNImputer(opts?: object): KNNImputer;
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' |
Defined in: generated/impute/KNNImputer.ts:25
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
dispose(): Promise<void>;
Promise
<void
>
Defined in: generated/impute/KNNImputer.ts:136
Fit the imputer on X.
fit(opts: object): Promise<any>;
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. |
Promise
<any
>
Defined in: generated/impute/KNNImputer.ts:153
Fit to data, then transform it.
Fits transformer to X
and y
with optional parameters fit\_params
and returns a transformed version of X
.
fit_transform(opts: object): Promise<any[]>;
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). |
Promise
<any
[]>
Defined in: generated/impute/KNNImputer.ts:193
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/impute/KNNImputer.ts:240
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/impute/KNNImputer.ts:278
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/impute/KNNImputer.ts:90
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/impute/KNNImputer.ts:315
Impute all missing values in X.
transform(opts: object): Promise<ArrayLike[]>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.X? |
ArrayLike [] |
The input data to complete. |
Promise
<ArrayLike
[]>
Defined in: generated/impute/KNNImputer.ts:348
boolean
=false
Defined in: generated/impute/KNNImputer.ts:23
boolean
=false
Defined in: generated/impute/KNNImputer.ts:22
PythonBridge
Defined in: generated/impute/KNNImputer.ts:21
string
Defined in: generated/impute/KNNImputer.ts:18
any
Defined in: generated/impute/KNNImputer.ts:19
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/impute/KNNImputer.ts:429
Indicator used to add binary indicators for missing values. undefined
if add_indicator is false
.
indicator_(): Promise<any>;
Promise
<any
>
Defined in: generated/impute/KNNImputer.ts:381
Number of features seen during fit.
n_features_in_(): Promise<number>;
Promise
<number
>
Defined in: generated/impute/KNNImputer.ts:404
py(): PythonBridge;
PythonBridge
Defined in: generated/impute/KNNImputer.ts:77
py(pythonBridge: PythonBridge): void;
Name | Type |
---|---|
pythonBridge |
PythonBridge |
void
Defined in: generated/impute/KNNImputer.ts:81