@@ -134,7 +134,7 @@ class SimpleImputer(_BaseImputer):
134
134
nullable integer dtypes with missing values, `missing_values`
135
135
should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.
136
136
137
- strategy : string , default='mean'
137
+ strategy : str , default='mean'
138
138
The imputation strategy.
139
139
140
140
- If "mean", then replace missing values using the mean along
@@ -150,25 +150,25 @@ class SimpleImputer(_BaseImputer):
150
150
.. versionadded:: 0.20
151
151
strategy="constant" for fixed value imputation.
152
152
153
- fill_value : string or numerical value, default=None
153
+ fill_value : str or numerical value, default=None
154
154
When strategy == "constant", fill_value is used to replace all
155
155
occurrences of missing_values.
156
156
If left to the default, fill_value will be 0 when imputing numerical
157
157
data and "missing_value" for strings or object data types.
158
158
159
- verbose : integer , default=0
159
+ verbose : int , default=0
160
160
Controls the verbosity of the imputer.
161
161
162
- copy : boolean , default=True
163
- If True, a copy of X will be created. If False, imputation will
162
+ copy : bool , default=True
163
+ If True, a copy of `X` will be created. If False, imputation will
164
164
be done in-place whenever possible. Note that, in the following cases,
165
165
a new copy will always be made, even if `copy=False`:
166
166
167
- - If X is not an array of floating values;
168
- - If X is encoded as a CSR matrix;
169
- - If add_indicator=True.
167
+ - If `X` is not an array of floating values;
168
+ - If `X` is encoded as a CSR matrix;
169
+ - If ` add_indicator=True` .
170
170
171
- add_indicator : boolean , default=False
171
+ add_indicator : bool , default=False
172
172
If True, a :class:`MissingIndicator` transform will stack onto output
173
173
of the imputer's transform. This allows a predictive estimator
174
174
to account for missingness despite imputation. If a feature has no
@@ -186,7 +186,7 @@ class SimpleImputer(_BaseImputer):
186
186
187
187
indicator_ : :class:`~sklearn.impute.MissingIndicator`
188
188
Indicator used to add binary indicators for missing values.
189
- `` None`` if add_indicator is False.
189
+ `None` if ` add_indicator= False` .
190
190
191
191
n_features_in_ : int
192
192
Number of features seen during :term:`fit`.
@@ -203,6 +203,11 @@ class SimpleImputer(_BaseImputer):
203
203
--------
204
204
IterativeImputer : Multivariate imputation of missing values.
205
205
206
+ Notes
207
+ -----
208
+ Columns which only contained missing values at :meth:`fit` are discarded
209
+ upon :meth:`transform` if strategy is not `"constant"`.
210
+
206
211
Examples
207
212
--------
208
213
>>> import numpy as np
@@ -215,12 +220,6 @@ class SimpleImputer(_BaseImputer):
215
220
[[ 7. 2. 3. ]
216
221
[ 4. 3.5 6. ]
217
222
[10. 3.5 9. ]]
218
-
219
- Notes
220
- -----
221
- Columns which only contained missing values at :meth:`fit` are discarded
222
- upon :meth:`transform` if strategy is not "constant".
223
-
224
223
"""
225
224
226
225
def __init__ (
@@ -301,17 +300,21 @@ def _validate_input(self, X, in_fit):
301
300
return X
302
301
303
302
def fit (self , X , y = None ):
304
- """Fit the imputer on X .
303
+ """Fit the imputer on `X` .
305
304
306
305
Parameters
307
306
----------
308
307
X : {array-like, sparse matrix}, shape (n_samples, n_features)
309
- Input data, where ``n_samples`` is the number of samples and
310
- ``n_features`` is the number of features.
308
+ Input data, where `n_samples` is the number of samples and
309
+ `n_features` is the number of features.
310
+
311
+ y : Ignored
312
+ Not used, present here for API consistency by convention.
311
313
312
314
Returns
313
315
-------
314
- self : SimpleImputer
316
+ self : object
317
+ Fitted estimator.
315
318
"""
316
319
X = self ._validate_input (X , in_fit = True )
317
320
@@ -449,7 +452,7 @@ def _dense_fit(self, X, strategy, missing_values, fill_value):
449
452
return np .full (X .shape [1 ], fill_value , dtype = X .dtype )
450
453
451
454
def transform (self , X ):
452
- """Impute all missing values in X .
455
+ """Impute all missing values in `X` .
453
456
454
457
Parameters
455
458
----------
@@ -538,10 +541,10 @@ def inverse_transform(self, X):
538
541
This operation can only be performed after :class:`SimpleImputer` is
539
542
instantiated with `add_indicator=True`.
540
543
541
- Note that `` inverse_transform` ` can only invert the transform in
544
+ Note that `inverse_transform` can only invert the transform in
542
545
features that have binary indicators for missing values. If a feature
543
- has no missing values at `` fit` ` time, the feature won't have a binary
544
- indicator, and the imputation done at `` transform` ` time won't be
546
+ has no missing values at `fit` time, the feature won't have a binary
547
+ indicator, and the imputation done at `transform` time won't be
545
548
inverted.
546
549
547
550
.. versionadded:: 0.24
@@ -556,7 +559,7 @@ def inverse_transform(self, X):
556
559
Returns
557
560
-------
558
561
X_original : ndarray of shape (n_samples, n_features)
559
- The original X with missing values as it was prior
562
+ The original `X` with missing values as it was prior
560
563
to imputation.
561
564
"""
562
565
check_is_fitted (self )
0 commit comments