Skip to content

Commit

Permalink
Fix dmlc#3730: scikit-learn 0.20 compatibility fix
Browse files Browse the repository at this point in the history
sklearn.cross_validation has been removed from scikit-learn 0.20,
so replace it with sklearn.model_selection
  • Loading branch information
hcho3 committed Sep 27, 2018
1 parent fbe9d41 commit b67f229
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion tests/python-gpu/test_gpu_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def non_decreasing(self, L):
# Test case for a bug where multiple batch predictions made on a test set produce incorrect results
def test_multi_predict(self):
from sklearn.datasets import make_regression
from sklearn.cross_validation import train_test_split
try:
from sklearn.model_selection import train_test_split
except:
from sklearn.cross_validation import train_test_split

n = 1000
X, y = make_regression(n, random_state=rng)
Expand Down
25 changes: 20 additions & 5 deletions tests/python/test_with_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def test_boston_housing_regression():
tm._skip_if_no_sklearn()
from sklearn.metrics import mean_squared_error
from sklearn.datasets import load_boston
from sklearn.cross_validation import KFold
try:
from sklearn.model_selection import KFold
except:
from sklearn.cross_validation import KFold

boston = load_boston()
y = boston['target']
Expand Down Expand Up @@ -191,7 +194,10 @@ def test_regression_with_custom_objective():
tm._skip_if_no_sklearn()
from sklearn.metrics import mean_squared_error
from sklearn.datasets import load_boston
from sklearn.cross_validation import KFold
try:
from sklearn.model_selection import KFold
except:
from sklearn.cross_validation import KFold

def objective_ls(y_true, y_pred):
grad = (y_pred - y_true)
Expand Down Expand Up @@ -224,7 +230,10 @@ def dummy_objective(y_true, y_pred):
def test_classification_with_custom_objective():
tm._skip_if_no_sklearn()
from sklearn.datasets import load_digits
from sklearn.cross_validation import KFold
try:
from sklearn.model_selection import KFold
except:
from sklearn.cross_validation import KFold

def logregobj(y_true, y_pred):
y_pred = 1.0 / (1.0 + np.exp(-y_pred))
Expand Down Expand Up @@ -263,7 +272,10 @@ def dummy_objective(y_true, y_preds):
def test_sklearn_api():
tm._skip_if_no_sklearn()
from sklearn.datasets import load_iris
from sklearn.cross_validation import train_test_split
try:
from sklearn.model_selection import train_test_split
except:
from sklearn.cross_validation import train_test_split

iris = load_iris()
tr_d, te_d, tr_l, te_l = train_test_split(iris.data, iris.target, train_size=120)
Expand All @@ -280,7 +292,10 @@ def test_sklearn_api():
def test_sklearn_api_gblinear():
tm._skip_if_no_sklearn()
from sklearn.datasets import load_iris
from sklearn.cross_validation import train_test_split
try:
from sklearn.model_selection import train_test_split
except:
from sklearn.cross_validation import train_test_split

iris = load_iris()
tr_d, te_d, tr_l, te_l = train_test_split(iris.data, iris.target, train_size=120)
Expand Down

0 comments on commit b67f229

Please sign in to comment.