1+ sklearn / dummy .py :290 :1 : W293 blank line contains whitespace
2+ sklearn / dummy .py :341 :80 : E501 line too long (94 > 79 characters )
3+ sklearn / dummy .py :351 :80 : E501 line too long (82 > 79 characters )
4+ sklearn / dummy .py :388 :1 : W391 blank line at end of file
5+ maheshakya @maheshakya - TECRA - M11 :~ / scikit - learn $ autopep8 sklearn / tests / test_dummy .py
16import warnings
27import numpy as np
38
@@ -59,6 +64,19 @@ def _check_behavior_2d(clf):
5964 assert_equal (y .shape , y_pred .shape )
6065
6166
67+ def _check_behavior_2d_for_constant (clf ):
68+ # 2d case only
69+ X = np .array ([[0 ], [0 ], [0 ], [0 ]]) # ignored
70+ y = np .array ([[1 , 0 , 5 , 4 , 3 ],
71+ [2 , 0 , 1 , 2 , 5 ],
72+ [1 , 0 , 4 , 5 , 2 ],
73+ [1 , 3 , 3 , 2 , 0 ]])
74+ est = clone (clf )
75+ est .fit (X , y )
76+ y_pred = est .predict (X )
77+ assert_equal (y .shape , y_pred .shape )
78+
79+
6280def test_most_frequent_strategy ():
6381 X = [[0 ], [0 ], [0 ], [0 ]] # ignored
6482 y = [1 , 2 , 1 , 1 ]
@@ -175,7 +193,7 @@ def test_classifier_exceptions():
175193 assert_raises (ValueError , clf .predict_proba , [])
176194
177195
178- def test_regressor ():
196+ def test_mean_strategy_regressor ():
179197 X = [[0 ]] * 4 # ignored
180198 y = [1 , 2 , 1 , 1 ]
181199
@@ -184,7 +202,7 @@ def test_regressor():
184202 assert_array_equal (reg .predict (X ), [5. / 4 ] * len (X ))
185203
186204
187- def test_multioutput_regressor ():
205+ def test_mean_strategy_multioutput_regressor ():
188206
189207 X_learn = np .random .randn (10 , 10 )
190208 y_learn = np .random .randn (10 , 5 )
@@ -210,6 +228,66 @@ def test_regressor_exceptions():
210228 assert_raises (ValueError , reg .predict , [])
211229
212230
231+ def test_median_strategy_regressor ():
232+ X = [[0 ]] * 5 # ignored
233+ y = [1 , 2 , 4 , 6 , 8 ]
234+
235+ reg = DummyRegressor (strategy = "median" )
236+ reg .fit (X , y )
237+ assert_array_equal (reg .predict (X ), [4 ] * len (X ))
238+
239+
240+ def test_median_strategy_multioutput_regressor ():
241+
242+ X_learn = np .random .randn (10 , 10 )
243+ y_learn = np .random .randn (10 , 5 )
244+
245+ median = np .median (y_learn , axis = 0 ).reshape ((1 , - 1 ))
246+
247+ X_test = np .random .randn (20 , 10 )
248+ y_test = np .random .randn (20 , 5 )
249+
250+ # Correctness oracle
251+ est = DummyRegressor (strategy = "median" )
252+ est .fit (X_learn , y_learn )
253+ y_pred_learn = est .predict (X_learn )
254+ y_pred_test = est .predict (X_test )
255+
256+ assert_array_equal (np .tile (median , (y_learn .shape [0 ], 1 )), y_pred_learn )
257+ assert_array_equal (np .tile (median , (y_test .shape [0 ], 1 )), y_pred_test )
258+ _check_behavior_2d (est )
259+
260+
261+ def test_constant_strategy_regressor ():
262+ X = [[0 ]] * 5 # ignored
263+ y = [1 , 2 , 4 , 6 , 8 ]
264+
265+ reg = DummyRegressor (strategy = "constant" , constant = [43 ])
266+ reg .fit (X , y )
267+ assert_array_equal (reg .predict (X ), [43 ] * len (X ))
268+
269+
270+ def test_constant_strategy_multioutput_regressor ():
271+
272+ X_learn = np .random .randn (10 , 10 )
273+ y_learn = np .random .randn (10 , 5 )
274+
275+ constants = np .random .randn (1 , 5 )
276+
277+ X_test = np .random .randn (20 , 10 )
278+ y_test = np .random .randn (20 , 5 )
279+
280+ # Correctness oracle
281+ est = DummyRegressor (strategy = "constant" , constant = constants )
282+ est .fit (X_learn , y_learn )
283+ y_pred_learn = est .predict (X_learn )
284+ y_pred_test = est .predict (X_test )
285+
286+ assert_array_equal (np .tile (constants , (y_learn .shape [0 ], 1 )), y_pred_learn )
287+ assert_array_equal (np .tile (constants , (y_test .shape [0 ], 1 )), y_pred_test )
288+ _check_behavior_2d_for_constant (est )
289+
290+
213291def test_constant_strategy ():
214292 X = [[0 ], [0 ], [0 ], [0 ]] # ignored
215293 y = [2 , 1 , 2 , 2 ]
@@ -253,3 +331,4 @@ def test_constant_strategy_exceptions():
253331 clf = DummyClassifier (strategy = "constant" , random_state = 0 ,
254332 constant = [2 , 0 ])
255333 assert_raises (ValueError , clf .fit , X , y )
334+
0 commit comments