Add examples for imputation
# License: BSD 3 clause
import warnings
-from time import time
import numbers
import numpy as np
@@ -139,6 +138,22 @@ class SimpleImputer(BaseEstimator, TransformerMixin):
statistics_ : array of shape (n_features,)
The imputation fill value for each feature.
+ Examples
+ --------
+ >>> import numpy as np
+ >>> from sklearn.impute import SimpleImputer
+ >>> imp_mean = SimpleImputer(missing_values=np.nan, strategy='mean')
+ >>> imp_mean.fit([[7, 2, 3], [4, np.nan, 6], [10, 5, 9]])
+ ... # doctest: +NORMALIZE_WHITESPACE
+ SimpleImputer(copy=True, fill_value=None, missing_values=nan,
+ strategy='mean', verbose=0)
+ >>> X = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]
+ >>> print(imp_mean.transform(X))
+ ... # doctest: +NORMALIZE_WHITESPACE
+ [[ 7. 2. 3. ]
+ [ 4. 3.5 6. ]
+ [10. 3.5 9. ]]
+
Notes
-----
Columns which only contained missing values at `fit` are discarded upon
@@ -340,7 +355,7 @@ class SimpleImputer(BaseEstimator, TransformerMixin):
Parameters
----------
- X : {array-like, sparse matrix}, shape = [n_samples, n_features]
+ X : {array-like, sparse matrix}, shape (n_samples, n_features)
The input data to complete.
"""
check_is_fitted(self, 'statistics_')
