8000 TST speed up comment tests by ~20% · scikit-learn/scikit-learn@5930097 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5930097

Browse files
committed
TST speed up comment tests by ~20%
See #339.
1 parent 1479b6c commit 5930097

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

sklearn/tests/test_common.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ def test_transformers():
179179
# than the number of features.
180180
# So we impose a smaller number (avoid "auto" mode)
181181
transformer.n_components = 1
182+
elif name == "MiniBatchDictionaryLearning":
183+
transformer.set_params(n_iter=5) # default = 1000
182184

183185
# fit
184186

@@ -677,14 +679,27 @@ def test_classifiers_pickle():
677679
assert_true(succeeded)
678680

679681

682+
BOSTON = None
683+
684+
685+
def _boston_subset():
686+
global BOSTON
687+
if BOSTON is None:
688+
boston = load_boston()
689+
X, y = boston.data, boston.target
690+
X, y = shuffle(X, y, random_state=0)
691+
X, y = X[:200], y[:200]
692+
X = StandardScaler().fit_transform(X)
693+
BOSTON = X, y
694+
return BOSTON
695+
696+
680697
def test_regressors_int():
681698
# test if regressors can cope with integer labels (by converting them to
682699
# float)
683700
regressors = all_estimators(type_filter='regressor')
684-
boston = load_boston()
685-
X, y = boston.data, boston.target
686-
X, y = shuffle(X, y, random_state=0)
687-
X = StandardScaler().fit_transform(X)
701+
X, _ = _boston_subset()
702+
X = X[:50]
688703
rnd = np.random.RandomState(0)
689704
y = rnd.randint(2, size=X.shape[0])
690705
for name, Regressor in regressors:
@@ -714,13 +729,10 @@ def test_regressors_int():
714729

715730
def test_regressors_train():
716731
regressors = all_estimators(type_filter='regressor')
717-
boston = load_boston()
718-
X, y = boston.data, boston.target
719-
X, y = shuffle(X, y, random_state=0)
720732
# TODO: test with intercept
721733
# TODO: test with multiple responses
722-
X = StandardScaler().fit_transform(X)
723-
y = StandardScaler().fit_transform(y)
734+
X, y = _boston_subset()
735+
y = StandardScaler().fit_transform(y) # X is already scaled
724736
rnd = np.random.RandomState(0)
725737
succeeded = True
726738
for name, Regressor in regressors:
@@ -760,13 +772,10 @@ def test_regressor_pickle():
760772
# Test that estimators can be pickled, and once pickled
761773
# give the same answer as before.
762774
regressors = all_estimators(type_filter='regressor')
763-
boston = load_boston()
764-
X, y = boston.data, boston.target
765-
X, y = shuffle(X, y, random_state=0)
775+
X, y = _boston_subset()
766776
# TODO: test with intercept
767777
# TODO: test with multiple responses
768-
X = StandardScaler().fit_transform(X)
769-
y = StandardScaler().fit_transform(y)
778+
y = StandardScaler().fit_transform(y) # X is already scaled
770779
rnd = np.random.RandomState(0)
771780
succeeded = True
772781
for name, Regressor in regressors:

0 commit comments

Comments
 (0)
0