Skip to content

Commit 25de6f3

Browse files
committed
Maintenance for tests (train_test_split)
1 parent 564d272 commit 25de6f3

6 files changed

+136
-16
lines changed

tests/test_func_api_classification_binary.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import scipy.stats as st
2626
from sklearn.model_selection import cross_val_predict
2727
from sklearn.model_selection import cross_val_score
28-
from sklearn.model_selection import train_test_split
28+
# from sklearn.model_selection import train_test_split
2929
from sklearn.model_selection import StratifiedKFold
3030
from sklearn.datasets import make_classification
3131
from sklearn.metrics import accuracy_score
@@ -41,7 +41,27 @@
4141

4242
X, y = make_classification(n_samples = 500, n_features = 5, n_informative = 3, n_redundant = 1,
4343
n_classes = n_classes, flip_y = 0, random_state = 0)
44-
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
44+
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
45+
46+
47+
# Make train/test split by hand to avoid strange errors probably related to testing suit:
48+
# https://github.com/scikit-learn/scikit-learn/issues/1684
49+
# https://github.com/scikit-learn/scikit-learn/issues/1704
50+
# Note: Python 2.7, 3.4 - OK, but 3.5, 3.6 - error
51+
52+
np.random.seed(0)
53+
ind = np.arange(500)
54+
np.random.shuffle(ind)
55+
56+
ind_train = ind[:400]
57+
ind_test = ind[400:]
58+
59+
X_train = X[ind_train]
60+
X_test = X[ind_test]
61+
62+
y_train = y[ind_train]
63+
y_test = y[ind_test]
64+
4565

4666
#-------------------------------------------------------------------------------
4767
#-------------------------------------------------------------------------------

tests/test_func_api_classification_multiclass.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import scipy.stats as st
2323
from sklearn.model_selection import cross_val_predict
2424
from sklearn.model_selection import cross_val_score
25-
from sklearn.model_selection import train_test_split
25+
# from sklearn.model_selection import train_test_split
2626
from sklearn.model_selection import StratifiedKFold
2727
from sklearn.datasets import make_classification
2828
from sklearn.metrics import accuracy_score
@@ -38,7 +38,27 @@
3838

3939
X, y = make_classification(n_samples = 500, n_features = 5, n_informative = 3, n_redundant = 1,
4040
n_classes = n_classes, flip_y = 0, random_state = 0)
41-
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
41+
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
42+
43+
44+
# Make train/test split by hand to avoid strange errors probably related to testing suit:
45+
# https://github.com/scikit-learn/scikit-learn/issues/1684
46+
# https://github.com/scikit-learn/scikit-learn/issues/1704
47+
# Note: Python 2.7, 3.4 - OK, but 3.5, 3.6 - error
48+
49+
np.random.seed(0)
50+
ind = np.arange(500)
51+
np.random.shuffle(ind)
52+
53+
ind_train = ind[:400]
54+
ind_test = ind[400:]
55+
56+
X_train = X[ind_train]
57+
X_test = X[ind_test]
58+
59+
y_train = y[ind_train]
60+
y_test = y[ind_test]
61+
4262

4363
#-------------------------------------------------------------------------------
4464
#-------------------------------------------------------------------------------

tests/test_func_api_regression.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from scipy.sparse import coo_matrix
2525
from sklearn.model_selection import cross_val_predict
2626
from sklearn.model_selection import cross_val_score
27-
from sklearn.model_selection import train_test_split
27+
# from sklearn.model_selection import train_test_split
2828
from sklearn.model_selection import KFold
2929
from sklearn.datasets import load_boston
3030
from sklearn.metrics import mean_absolute_error
@@ -39,7 +39,27 @@
3939

4040
boston = load_boston()
4141
X, y = boston.data, boston.target
42-
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
42+
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
43+
44+
45+
# Make train/test split by hand to avoid strange errors probably related to testing suit:
46+
# https://github.com/scikit-learn/scikit-learn/issues/1684
47+
# https://github.com/scikit-learn/scikit-learn/issues/1704
48+
# Note: Python 2.7, 3.4 - OK, but 3.5, 3.6 - error
49+
50+
np.random.seed(0)
51+
ind = np.arange(500)
52+
np.random.shuffle(ind)
53+
54+
ind_train = ind[:400]
55+
ind_test = ind[400:]
56+
57+
X_train = X[ind_train]
58+
X_test = X[ind_test]
59+
60+
y_train = y[ind_train]
61+
y_test = y[ind_test]
62+
4363

4464
#-------------------------------------------------------------------------------
4565
#-------------------------------------------------------------------------------

tests/test_sklearn_api_classification_binary.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import scipy.stats as st
2525
from sklearn.model_selection import cross_val_predict
2626
from sklearn.model_selection import cross_val_score
27-
from sklearn.model_selection import train_test_split
27+
# from sklearn.model_selection import train_test_split
2828
# from sklearn.model_selection import KFold
2929
from sklearn.model_selection import StratifiedKFold
3030
from sklearn.datasets import make_classification
@@ -48,9 +48,29 @@
4848
n_classes=n_classes, flip_y=0,
4949
random_state=0)
5050

51-
X_train, X_test, y_train, y_test = train_test_split(X, y,
52-
test_size=0.2,
53-
random_state=0)
51+
# X_train, X_test, y_train, y_test = train_test_split(X, y,
52+
# test_size=0.2,
53+
# random_state=0)
54+
55+
56+
# Make train/test split by hand to avoid strange errors probably related to testing suit:
57+
# https://github.com/scikit-learn/scikit-learn/issues/1684
58+
# https://github.com/scikit-learn/scikit-learn/issues/1704
59+
# Note: Python 2.7, 3.4 - OK, but 3.5, 3.6 - error
60+
61+
np.random.seed(0)
62+
ind = np.arange(500)
63+
np.random.shuffle(ind)
64+
65+
ind_train = ind[:400]
66+
ind_test = ind[400:]
67+
68+
X_train = X[ind_train]
69+
X_test = X[ind_test]
70+
71+
y_train = y[ind_train]
72+
y_test = y[ind_test]
73+
5474

5575
#-------------------------------------------------------------------------------
5676
#-------------------------------------------------------------------------------

tests/test_sklearn_api_classification_multiclass.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import scipy.stats as st
2222
from sklearn.model_selection import cross_val_predict
2323
from sklearn.model_selection import cross_val_score
24-
from sklearn.model_selection import train_test_split
24+
# from sklearn.model_selection import train_test_split
2525
# from sklearn.model_selection import KFold
2626
from sklearn.model_selection import StratifiedKFold
2727
from sklearn.datasets import make_classification
@@ -45,9 +45,29 @@
4545
n_classes=n_classes, flip_y=0,
4646
random_state=0)
4747

48-
X_train, X_test, y_train, y_test = train_test_split(X, y,
49-
test_size=0.2,
50-
random_state=0)
48+
# X_train, X_test, y_train, y_test = train_test_split(X, y,
49+
# test_size=0.2,
50+
# random_state=0)
51+
52+
53+
# Make train/test split by hand to avoid strange errors probably related to testing suit:
54+
# https://github.com/scikit-learn/scikit-learn/issues/1684
55+
# https://github.com/scikit-learn/scikit-learn/issues/1704
56+
# Note: Python 2.7, 3.4 - OK, but 3.5, 3.6 - error
57+
58+
np.random.seed(0)
59+
ind = np.arange(500)
60+
np.random.shuffle(ind)
61+
62+
ind_train = ind[:400]
63+
ind_test = ind[400:]
64+
65+
X_train = X[ind_train]
66+
X_test = X[ind_test]
67+
68+
y_train = y[ind_train]
69+
y_test = y[ind_test]
70+
5171

5272
#-------------------------------------------------------------------------------
5373
#-------------------------------------------------------------------------------

tests/test_sklearn_api_regression.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from sklearn.base import RegressorMixin
2626
from sklearn.model_selection import cross_val_predict
2727
from sklearn.model_selection import cross_val_score
28-
from sklearn.model_selection import train_test_split
28+
# from sklearn.model_selection import train_test_split
2929
from sklearn.model_selection import KFold
3030
from sklearn.model_selection import GridSearchCV
3131
from sklearn.model_selection import RandomizedSearchCV
@@ -50,7 +50,27 @@
5050

5151
boston = load_boston()
5252
X, y = boston.data, boston.target
53-
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
53+
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
54+
55+
56+
# Make train/test split by hand to avoid strange errors probably related to testing suit:
57+
# https://github.com/scikit-learn/scikit-learn/issues/1684
58+
# https://github.com/scikit-learn/scikit-learn/issues/1704
59+
# Note: Python 2.7, 3.4 - OK, but 3.5, 3.6 - error
60+
61+
np.random.seed(0)
62+
ind = np.arange(500)
63+
np.random.shuffle(ind)
64+
65+
ind_train = ind[:400]
66+
ind_test = ind[400:]
67+
68+
X_train = X[ind_train]
69+
X_test = X[ind_test]
70+
71+
y_train = y[ind_train]
72+
y_test = y[ind_test]
73+
5474

5575
# -----------------------------------------------------------------------------
5676
# Scikit-learn INcompatible estimator

0 commit comments

Comments
 (0)