mojolearn.SimpleImputer#

class mojolearn.SimpleImputer(*, missing_values=nan, strategy='mean', fill_value=None, copy=True, add_indicator=False, keep_empty_features=False)[source]#

Bases: _PrepBase

Replace missing values with a per-column statistic.

Follows scikit-learn’s SimpleImputer for numeric data. Missing entries (missing_values) are replaced by each column’s mean, median, most frequent value or a constant. Input and output are float32.

A column with no observed values in fit is dropped from the output, unless keep_empty_features is set; then it is filled with 0 (or with fill_value under strategy='constant').

Parameters:
  • missing_values (float, default NaN) – Value that marks a missing entry.

  • strategy ({‘mean’, ‘median’, ‘most_frequent’, ‘constant’} or callable, default ‘mean’) – 'median' uses numpy’s linear percentile of the non-missing entries; 'most_frequent' picks the smallest value on a tie. A callable is called once per column, on the host, with the column’s non-missing values as a 1-D float32 array, and must return the column’s statistic; a NaN statistic drops the column unless keep_empty_features. Any other value raises ValueError.

  • fill_value (float or None, default None) – Value used by strategy='constant'; None means 0. Must be numeric (TypeError otherwise).

  • copy (bool, default True) – Accepted for scikit-learn compatibility; transform always returns a new array.

  • add_indicator (bool, default False) – Append missing-indicator columns (1.0 where missing) for the features that had a missing value in fit, as scikit-learn’s MissingIndicator.

  • keep_empty_features (bool, default False) – Keep columns that had no observed values in fit.

Variables:
  • statistics_ (array of shape (n_features,)) – Fill value of each column (NaN for an all-missing column unless keep_empty_features).

  • n_features_in_ (int) – Number of columns seen in fit.

  • numeric_mode_ (str) – Numeric mode the estimator was fitted in; transform runs in the same mode.

Examples

>>> import numpy as np, mojolearn
>>> X = np.array([[1.0, np.nan], [3.0, 4.0], [np.nan, 8.0]], dtype=np.float32)
>>> mojolearn.SimpleImputer(strategy="median").fit_transform(X)
__init__(*, missing_values=nan, strategy='mean', fill_value=None, copy=True, add_indicator=False, keep_empty_features=False)[source]#

Methods

fit(X[, y])

fit_transform(X[, y])

Fit to X, then transform X.

get_params([deep])

Return the constructor parameters as a dict.

set_params(**params)

Set constructor parameters.

transform(X)