mojolearn.SimpleImputer#
- class mojolearn.SimpleImputer(*, missing_values=nan, strategy='mean', fill_value=None, copy=True, add_indicator=False, keep_empty_features=False)[source]#
Bases:
_PrepBaseReplace missing values with a per-column statistic.
Follows scikit-learn’s
SimpleImputerfor 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_featuresis set; then it is filled with 0 (or withfill_valueunderstrategy='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 unlesskeep_empty_features. Any other value raisesValueError.fill_value (float or None, default None) – Value used by
strategy='constant'; None means 0. Must be numeric (TypeErrorotherwise).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:
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 transformX.get_params([deep])Return the constructor parameters as a dict.
set_params(**params)Set constructor parameters.
transform(X)