diff --git a/tests/python/test_interaction_constraints.py b/tests/python/test_interaction_constraints.py index 8af483a76..6ca842b92 100644 --- a/tests/python/test_interaction_constraints.py +++ b/tests/python/test_interaction_constraints.py @@ -2,7 +2,8 @@ import numpy as np import xgboost import unittest -from sklearn.metrics import accuracy_score +import testing as tm +import pytest dpath = 'demo/data/' rng = np.random.RandomState(1994) @@ -49,7 +50,9 @@ class TestInteractionConstraints(unittest.TestCase): diff2 = preds[2] - preds[1] assert np.all(np.abs(diff2 - diff2[0]) < 1e-4) + @pytest.mark.skipif(**tm.no_sklearn()) def test_training_accuracy(self, tree_method='hist'): + from sklearn.metrics import accuracy_score dtrain = xgboost.DMatrix(dpath + 'agaricus.txt.train?indexing_mode=1') dtest = xgboost.DMatrix(dpath + 'agaricus.txt.test?indexing_mode=1') params = { diff --git a/tests/python/test_monotone_constraints.py b/tests/python/test_monotone_constraints.py index 22df36f63..97cb45fc0 100644 --- a/tests/python/test_monotone_constraints.py +++ b/tests/python/test_monotone_constraints.py @@ -1,10 +1,12 @@ import numpy as np import xgboost as xgb import unittest -from sklearn.metrics import accuracy_score +import testing as tm +import pytest dpath = 'demo/data/' + def is_increasing(y): return np.count_nonzero(np.diff(y) < 0.0) == 0 @@ -100,7 +102,9 @@ class TestMonotoneConstraints(unittest.TestCase): assert is_correctly_constrained(constrained_hist_method) + @pytest.mark.skipif(**tm.no_sklearn()) def test_training_accuracy(self): + from sklearn.metrics import accuracy_score dtrain = xgb.DMatrix(dpath + 'agaricus.txt.train?indexing_mode=1') dtest = xgb.DMatrix(dpath + 'agaricus.txt.test?indexing_mode=1') params = {'eta': 1, 'max_depth': 6, 'objective': 'binary:logistic', diff --git a/tests/python/test_ranking.py b/tests/python/test_ranking.py index 331686b2d..dc257cf23 100644 --- a/tests/python/test_ranking.py +++ b/tests/python/test_ranking.py @@ -1,12 +1,9 @@ import numpy as np from scipy.sparse import csr_matrix import xgboost -import sys import os -from sklearn.datasets import load_svmlight_files import unittest import itertools -import glob import shutil import urllib.request import zipfile @@ -36,6 +33,7 @@ def test_ranking_with_unweighted_data(): auc_rec = evals_result['train']['aucpr'] assert all(p <= q for p, q in zip(auc_rec, auc_rec[1:])) + def test_ranking_with_weighted_data(): Xrow = np.array([1, 2, 6, 8, 11, 14, 16, 17]) Xcol = np.array([0, 0, 1, 1, 2, 2, 3, 3]) @@ -82,6 +80,7 @@ class TestRanking(unittest.TestCase): """ Download and setup the test fixtures """ + from sklearn.datasets import load_svmlight_files # download the test data cls.dpath = 'demo/rank/' src = 'https://s3-us-west-2.amazonaws.com/xgboost-examples/MQ2008.zip' @@ -91,7 +90,8 @@ class TestRanking(unittest.TestCase): with zipfile.ZipFile(target, 'r') as f: f.extractall(path=cls.dpath) - x_train, y_train, qid_train, x_test, y_test, qid_test, x_valid, y_valid, qid_valid = load_svmlight_files( + (x_train, y_train, qid_train, x_test, y_test, qid_test, + x_valid, y_valid, qid_valid) = load_svmlight_files( (cls.dpath + "MQ2008/Fold1/train.txt", cls.dpath + "MQ2008/Fold1/test.txt", cls.dpath + "MQ2008/Fold1/vali.txt"),