Skip to content

Commit db6494c

Browse files
committed
FIX remove all unseeded random variables from common tests.
1 parent 6d9935b commit db6494c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

sklearn/tests/test_common.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def test_classifiers_pickle():
671671
assert_array_almost_equal(pickled_y_pred, y_pred)
672672
except Exception, exc:
673673
succeeded = False
674-
print ("Esimator %s doesn't predict the same value "
674+
print ("Estimator %s doesn't predict the same value "
675675
"after pickling" % name)
676676
raise exc
677677
assert_true(succeeded)
@@ -685,7 +685,8 @@ def test_regressors_int():
685685
X, y = boston.data, boston.target
686686
X, y = shuffle(X, y, random_state=0)
687687
X = StandardScaler().fit_transform(X)
688-
y = np.random.randint(2, size=X.shape[0])
688+
rnd = np.random.RandomState(0)
689+
y = rnd.randint(2, size=X.shape[0])
689690
for name, Regressor in regressors:
690691
if name in dont_test or name in ('CCA',):
691692
continue
@@ -698,7 +699,7 @@ def test_regressors_int():
698699
set_random_state(regressor_2)
699700

700701
if name in ('_PLS', 'PLSCanonical', 'PLSRegression'):
701-
y_ = np.vstack([y, 2 * y + np.random.randint(2, size=len(y))])
702+
y_ = np.vstack([y, 2 * y + rnd.randint(2, size=len(y))])
702703
y_ = y_.T
703704
else:
704705
y_ = y
@@ -720,6 +721,7 @@ def test_regressors_train():
720721
# TODO: test with multiple responses
721722
X = StandardScaler().fit_transform(X)
722723
y = StandardScaler().fit_transform(y)
724+
rnd = np.random.RandomState(0)
723725
succeeded = True
724726
for name, Regressor in regressors:
725727
if name in dont_test:
@@ -736,7 +738,7 @@ def test_regressors_train():
736738
# fit
737739
try:
738740
if name in ('_PLS', 'PLSCanonical', 'PLSRegression', 'CCA'):
739-
y_ = np.vstack([y, 2 * y + np.random.randint(2, size=len(y))])
741+
y_ = np.vstack([y, 2 * y + rnd.randint(2, size=len(y))])
740742
y_ = y_.T
741743
else:
742744
y_ = y
@@ -765,6 +767,7 @@ def test_regressor_pickle():
765767
# TODO: test with multiple responses
766768
X = StandardScaler().fit_transform(X)
767769
y = StandardScaler().fit_transform(y)
770+
rnd = np.random.RandomState(0)
768771
succeeded = True
769772
for name, Regressor in regressors:
770773
if name in dont_test:
@@ -777,7 +780,7 @@ def test_regressor_pickle():
777780
regressor.alpha = 0.01
778781

779782
if name in ('_PLS', 'PLSCanonical', 'PLSRegression', 'CCA'):
780-
y_ = np.vstack([y, 2 * y + np.random.randint(2, size=len(y))])
783+
y_ = np.vstack([y, 2 * y + rnd.randint(2, size=len(y))])
781784
y_ = y_.T
782785
else:
783786
y_ = y
@@ -792,7 +795,7 @@ def test_regressor_pickle():
792795
assert_array_almost_equal(pickled_y_pred, y_pred)
793796
except Exception, exc:
794797
succeeded = False
795-
print ("Esimator %s doesn't predict the same value "
798+
print ("Estimator %s doesn't predict the same value "
796799
"after pickling" % name)
797800
raise exc
798801
assert_true(succeeded)

0 commit comments

Comments
 (0)