@@ -405,6 +405,9 @@ class MissingIndicator(BaseEstimator, TransformerMixin):
405
405
The features with missing values.
406
406
Note that this is only stored if features == 'train
407
407
408
+ n_features_ : int
409
+ The number of features during fit time.
410
+
408
411
Example
409
412
-------
410
413
>>> from sklearn.preprocessing import MissingIndicator
@@ -436,7 +439,7 @@ def __init__(self, missing_values="NaN", features="train", sparse="auto"):
436
439
self .features = features
437
440
self .sparse = sparse
438
441
439
- def fit (self , X ):
442
+ def fit (self , X , y = None ):
440
443
"""Fit the transformer on X.
441
444
442
445
Parameters
@@ -463,8 +466,8 @@ def fit(self, X):
463
466
raise ValueError ("sparse can only use be boolean or 'auto'"
464
467
" got {0}" .format (self .sparse ))
465
468
466
- X = check_array (X , accept_sparse = ('csc' , 'csr' ), dtype = np .float64 ,
467
- force_all_finite = False )
469
+ X = check_array (X , accept_sparse = ('csc' , 'csr' ), dtype = np .float64 )
470
+ self . n_features_ = X . shape [ 1 ]
468
471
469
472
if self .features == "train" :
470
473
_ , self .feat_with_missing_ = self ._get_missing_features_info (X )
@@ -488,14 +491,16 @@ def transform(self, X):
488
491
if self .features == "train" :
489
492
check_is_fitted (self , "feat_with_missing_" )
490
493
491
- X = check_array (X , accept_sparse = ('csc' , 'csr' ), dtype = np .float64 ,
492
- force_all_finite = False )
494
+ X = check_array (X , accept_sparse = ('csc' , 'csr' ), dtype = np .float64 )
495
+ if X .shape [1 ] != self .n_features_ :
496
+ raise ValueError ("X has a different shape than during fitting." )
497
+
493
498
imputer_mask , feat_with_missing = self ._get_missing_features_info (X )
494
499
495
500
if self .features == "train" :
496
501
features = np .setdiff1d (feat_with_missing ,
497
502
self .feat_with_missing_ )
498
- if features .size :
503
+ if features .size > 0 :
499
504
warnings .warn ("The features %s have missing values "
500
505
"in transform but have no missing values "
501
506
"in fit " % features , RuntimeWarning ,
0 commit comments