# SimpleImputer

### *class* cuml.preprocessing.SimpleImputer(\*args, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_imputation.py#L163)

Imputation transformer for completing missing values.

* **Parameters:**
  **missing_values**
  : 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`.

  **strategy**
  : The imputation strategy.
    - If “mean”, then replace missing values using the mean along
      each column. Can only be used with numeric data.
    - If “median”, then replace missing values using the median along
      each column. Can only be used with numeric data.
    - If “most_frequent”, then replace missing using the most frequent
      value along each column. Can be used with strings or numeric data.
    - If “constant”, then replace missing values with fill_value. Can be
      used with strings or numeric data.
    <br/>
    strategy=”constant” for fixed value imputation.

  **fill_value**
  : When strategy == “constant”, fill_value is used to replace all
    occurrences of missing_values.
    If left to the default, fill_value will be 0 when imputing numerical
    data and “missing_value” for strings or object data types.

  **verbose**
  : Controls the verbosity of the imputer.

  **copy**
  : 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`:
    - If X is not an array of floating values;
    - If X is encoded as a CSR matrix;
    - If add_indicator=True.

  **add_indicator**
  : If True, a [`MissingIndicator`](../cuml.preprocessing.MissingIndicator/index.html.md#cuml.preprocessing.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.
* **Attributes:**
  **statistics_**
  : The imputation fill value for each feature.
    Computing statistics can result in `np.nan` values.
    During [`transform()`](#cuml.preprocessing.SimpleImputer.transform), features corresponding to `np.nan`
    statistics will be discarded.

### Methods

| [`fit`](#cuml.preprocessing.SimpleImputer.fit)(X[, y])                             | Fit the imputer on X.                        |
|------------------------------------------------------------------------------------------|----------------------------------------------|
| [`get_feature_names_out`](#cuml.preprocessing.SimpleImputer.get_feature_names_out)([input_features]) | Get output feature names for transformation. |
| [`transform`](#cuml.preprocessing.SimpleImputer.transform)(X)                            | Impute all missing values in X.              |

#### SEE ALSO
`IterativeImputer`
: Multivariate imputation of missing values.

### Notes

Columns which only contained missing values at [`fit()`](#cuml.preprocessing.SimpleImputer.fit) are discarded
upon [`transform()`](#cuml.preprocessing.SimpleImputer.transform) if strategy is not “constant”.

### Examples

```pycon
>>> import cupy as cp
>>> from cuml.preprocessing import SimpleImputer
>>> imp_mean = SimpleImputer(missing_values=cp.nan, strategy='mean')
>>> imp_mean.fit(cp.asarray([[7, 2, 3], [4, cp.nan, 6], [10, 5, 9]]))
SimpleImputer()
>>> X = [[cp.nan, 2, 3], [4, cp.nan, 6], [10, cp.nan, 9]]
>>> print(imp_mean.transform(cp.asarray(X)))
[[ 7.   2.   3. ]
 [ 4.   3.5  6. ]
 [10.   3.5  9. ]]
```

<!-- !! processed by numpydoc !! -->

#### fit(X, y=None) → [SimpleImputer](#cuml.preprocessing.SimpleImputer)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_imputation.py#L319)

Fit the imputer on X.

* **Parameters:**
  **X**
  : Input data, where `n_samples` is the number of samples and
    `n_features` is the number of features.
* **Returns:**
  **self**

<!-- !! processed by numpydoc !! -->

#### fit_transform(X, y=None, \*\*fit_params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/utils/skl_dependencies.py#L42)

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:**
  **X**

  **y**
  : Target values.

  **\*\*fit_params**
  : Additional fit parameters.
* **Returns:**
  **X_new**
  : Transformed array.

<!-- !! processed by numpydoc !! -->

#### get_feature_names_out(input_features=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_imputation.py#L495)

Get output feature names for transformation.

* **Parameters:**
  **input_features**
  : Input feature names.
* **Returns:**
  **feature_names_out**
  : Transformed feature names.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn’t
have to override this method

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn’t have to override this method

<!-- !! processed by numpydoc !! -->

#### transform(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_imputation.py#L432)

Impute all missing values in X.

* **Parameters:**
  **X**
  : The input data to complete.

<!-- !! processed by numpydoc !! -->
