1616from sklearn .preprocessing import LabelEncoder
1717from sklearn .preprocessing import Normalizer
1818from sklearn .preprocessing import normalize
19- from sklearn .preprocessing import UnitVarianceScaler
19+ from sklearn .preprocessing import StandardScaler
2020from sklearn .preprocessing import scale
2121from sklearn .preprocessing import MinMaxScaler
2222
@@ -38,7 +38,7 @@ def test_scaler_1d():
3838 X = rng .randn (5 )
3939 X_orig_copy = X .copy ()
4040
41- scaler = UnitVarianceScaler ()
41+ scaler = StandardScaler ()
4242 X_scaled = scaler .fit (X ).transform (X , copy = False )
4343 assert_array_almost_equal (X_scaled .mean (axis = 0 ), 0.0 )
4444 assert_array_almost_equal (X_scaled .std (axis = 0 ), 1.0 )
@@ -49,7 +49,7 @@ def test_scaler_1d():
4949
5050 # Test with 1D list
5151 X = [0. , 1. , 2 , 0.4 , 1. ]
52- scaler = UnitVarianceScaler ()
52+ scaler = StandardScaler ()
5353 X_scaled = scaler .fit (X ).transform (X , copy = False )
5454 assert_array_almost_equal (X_scaled .mean (axis = 0 ), 0.0 )
5555 assert_array_almost_equal (X_scaled .std (axis = 0 ), 1.0 )
@@ -65,7 +65,7 @@ def test_scaler_2d_arrays():
6565 X = rng .randn (4 , 5 )
6666 X [:, 0 ] = 0.0 # first feature is always of zero
6767
68- scaler = UnitVarianceScaler ()
68+ scaler = StandardScaler ()
6969 X_scaled = scaler .fit (X ).transform (X , copy = True )
7070 assert_false (np .any (np .isnan (X_scaled )))
7171
@@ -99,7 +99,7 @@ def test_scaler_2d_arrays():
9999
100100 X = rng .randn (4 , 5 )
101101 X [:, 0 ] = 1.0 # first feature is a constant, non zero feature
102- scaler = UnitVarianceScaler ()
102+ scaler = StandardScaler ()
103103 X_scaled = scaler .fit (X ).transform (X , copy = True )
104104 assert_false (np .any (np .isnan (X_scaled )))
105105 assert_array_almost_equal (X_scaled .mean (axis = 0 ), 5 * [0.0 ])
@@ -113,19 +113,14 @@ def test_min_max_scaler():
113113 scaler = MinMaxScaler ()
114114 # default params
115115 X_trans = scaler .fit_transform (X )
116- assert_equal (X_trans .min (axis = 1 ), 0 )
117- assert_equal (X_trans .max (axis = 1 ), 1 )
116+ assert_equal (X_trans .min (axis = 0 ), 0 )
117+ assert_equal (X_trans .max (axis = 0 ), 1 )
118118
119119 # not default params
120120 scaler = MinMaxScaler (feature_range = (1 , 2 ))
121121 X_trans = scaler .fit_transform (X )
122- assert_equal (X_trans .min (axis = 1 ), 1 )
123- assert_equal (X_trans .max (axis = 1 ), 2 )
124-
125- # sparse
126- X_trans = scaler .fit_transform (sp .csr_matrix (X ))
127- assert_equal (X_trans .min (axis = 1 ), 1 )
128- assert_equal (X_trans .max (axis = 1 ), 2 )
122+ assert_equal (X_trans .min (axis = 0 ), 1 )
123+ assert_equal (X_trans .max (axis = 0 ), 2 )
129124
130125
131126def test_scaler_without_centering ():
@@ -134,11 +129,11 @@ def test_scaler_without_centering():
134129 X [:, 0 ] = 0.0 # first feature is always of zero
135130 X_csr = sp .csr_matrix (X )
136131
137- scaler = UnitVarianceScaler (with_mean = False ).fit (X )
132+ scaler = StandardScaler (with_mean = False ).fit (X )
138133 X_scaled = scaler .transform (X , copy = True )
139134 assert_false (np .any (np .isnan (X_scaled )))
140135
141- scaler_csr = UnitVarianceScaler (with_mean = False ).fit (X_csr )
136+ scaler_csr = StandardScaler (with_mean = False ).fit (X_csr )
142137 X_csr_scaled = scaler_csr .transform (X_csr , copy = True )
143138 assert_false (np .any (np .isnan (X_csr_scaled .data )))
144139
@@ -169,18 +164,18 @@ def test_scaler_without_centering():
169164
170165
171166def test_scaler_without_copy ():
172- """Check that UnitVarianceScaler .fit does not change input"""
167+ """Check that StandardScaler .fit does not change input"""
173168 rng = np .random .RandomState (42 )
174169 X = rng .randn (4 , 5 )
175170 X [:, 0 ] = 0.0 # first feature is always of zero
176171 X_csr = sp .csr_matrix (X )
177172
178173 X_copy = X .copy ()
179- UnitVarianceScaler (copy = False ).fit (X )
174+ StandardScaler (copy = False ).fit (X )
180175 assert_array_equal (X , X_copy )
181176
182177 X_csr_copy = X_csr .copy ()
183- UnitVarianceScaler (with_mean = False , copy = False ).fit (X_csr )
178+ StandardScaler (with_mean = False , copy = False ).fit (X_csr )
184179 assert_array_equal (X_csr .toarray (), X_csr_copy .toarray ())
185180
186181
@@ -191,10 +186,10 @@ def test_scale_sparse_with_mean_raise_exception():
191186
192187 # check scaling and fit with direct calls on sparse data
193188 assert_raises (ValueError , scale , X_csr , with_mean = True )
194- assert_raises (ValueError , UnitVarianceScaler (with_mean = True ).fit , X_csr )
189+ assert_raises (ValueError , StandardScaler (with_mean = True ).fit , X_csr )
195190
196191 # check transform and inverse_transform after a fit on a dense array
197- scaler = UnitVarianceScaler (with_mean = True ).fit (X )
192+ scaler = StandardScaler (with_mean = True ).fit (X )
198193 assert_raises (ValueError , scaler .transform , X_csr )
199194
200195 X_transformed_csr = sp .csr_matrix (scaler .transform (X ))
@@ -518,11 +513,11 @@ def test_label_binarizer_multilabel_unlabeled():
518513
519514
520515def test_center_kernel ():
521- """Test that KernelCenterer is equivalent to UnitVarianceScaler
516+ """Test that KernelCenterer is equivalent to StandardScaler
522517 in feature space"""
523518 rng = np .random .RandomState (0 )
524519 X_fit = rng .random_sample ((5 , 4 ))
525- scaler = UnitVarianceScaler (with_std = False )
520+ scaler = StandardScaler (with_std = False )
526521 scaler .fit (X_fit )
527522 X_fit_centered = scaler .transform (X_fit )
528523 K_fit = np .dot (X_fit , X_fit .T )
@@ -545,7 +540,7 @@ def test_center_kernel():
545540def test_fit_transform ():
546541 rng = np .random .RandomState (0 )
547542 X = rng .random_sample ((5 , 4 ))
548- for obj in ((UnitVarianceScaler (), Normalizer (), Binarizer ())):
543+ for obj in ((StandardScaler (), Normalizer (), Binarizer ())):
549544 X_transformed = obj .fit (X ).transform (X )
550545 X_transformed2 = obj .fit_transform (X )
551546 assert_array_equal (X_transformed , X_transformed2 )
0 commit comments