@@ -252,15 +252,36 @@ def data_range(self):
252
252
def data_min (self ):
253
253
return self .data_min_
254
254
255
+ def _reset (self ):
256
+ """Reset internal data-dependent state of the scaler, if necessary.
257
+
258
+ __init__ parameters are not touched.
259
+ """
260
+
261
+ # Checking one attribute is enough, becase they are all set together
262
+ # in partial_fit
263
+ if hasattr (self , 'scale_' ):
264
+ del self .scale_
265
+ del self .min_
266
+ del self .n_samples_seen_
267
+ del self .data_min_
268
+ del self .data_max_
269
+ del self .data_range_
270
+
255
271
def fit (self , X , y = None ):
256
272
"""Compute the minimum and maximum to be used for later scaling.
257
273
274
+ it always resets the object's internal state first.
275
+
258
276
Parameters
259
277
----------
260
278
X : array-like, shape [n_samples, n_features]
261
279
The data used to compute the per-feature minimum and maximum
262
280
used for later scaling along the features axis.
263
281
"""
282
+
283
+ # Reset internal state before fitting
284
+ self ._reset ()
264
285
return self .partial_fit (X , y )
265
286
266
287
def partial_fit (self , X , y = None ):
@@ -489,9 +510,25 @@ def __init__(self, copy=True, with_mean=True, with_std=True):
489
510
def std_ (self ):
490
511
return self .scale_
491
512
513
+ def _reset (self ):
514
+ """Reset internal data-dependent state of the scaler, if necessary.
515
+
516
+ __init__ parameters are not touched.
517
+ """
518
+
519
+ # Checking one attribute is enough, becase they are all set together
520
+ # in partial_fit
521
+ if hasattr (self , 'scale_' ):
522
+ del self .scale_
523
+ del self .n_samples_seen_
524
+ del self .mean_
525
+ del self .var_
526
+
492
527
def fit (self , X , y = None ):
493
528
"""Compute the mean and std to be used for later scaling.
494
529
530
+ it always resets the object's internal state first.
531
+
495
532
Parameters
496
533
----------
497
534
X : {array-like, sparse matrix}, shape [n_samples, n_features]
@@ -500,6 +537,9 @@ def fit(self, X, y=None):
500
537
501
538
y: Passthrough for ``Pipeline`` compatibility.
502
539
"""
540
+
541
+ # Reset internal state before fitting
542
+ self ._reset ()
503
543
return self .partial_fit (X , y )
504
544
505
545
def partial_fit (self , X , y = None ):
@@ -671,15 +711,33 @@ class MaxAbsScaler(BaseEstimator, TransformerMixin):
671
711
def __init__ (self , copy = True ):
672
712
self .copy = copy
673
713
714
+ def _reset (self ):
715
+ """Reset internal data-dependent state of the scaler, if necessary.
716
+
717
+ __init__ parameters are not touched.
718
+ """
719
+
720
+ # Checking one attribute is enough, becase they are all set together
721
+ # in partial_fit
722
+ if hasattr (self , 'scale_' ):
723
+ del self .scale_
724
+ del self .n_samples_seen_
725
+ del self .max_abs_
726
+
674
727
def fit (self , X , y = None ):
675
728
"""Compute the maximum absolute value to be used for later scaling.
676
729
730
+ it always resets the object's internal state first.
731
+
677
732
Parameters
678
733
----------
679
734
X : {array-like, sparse matrix}, shape [n_samples, n_features]
680
735
The data used to compute the per-feature minimum and maximum
681
736
used for later scaling along the features axis.
682
737
"""
738
+
739
+ # Reset internal state before fitting
740
+ self ._reset ()
683
741
return self .partial_fit (X , y )
684
742
685
743
def partial_fit (self , X , y = None ):
0 commit comments