8000 Add test for HTSCV · scikit-learn/scikit-learn@73f5661 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73f5661

Browse files
committed
Add test for HTSCV
1 parent 04b9e79 commit 73f5661

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

sklearn/model_selection/tests/test_split.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from sklearn.model_selection import KFold
3131
from sklearn.model_selection import StratifiedKFold
3232
from sklearn.model_selection import LabelKFold
33+
from sklearn.model_selection import HomogeneousTimeSeriesCV
3334
from sklearn.model_selection import LeaveOneOut
3435
from sklearn.model_selection import LeaveOneLabelOut
3536
from sklearn.model_selection import LeavePOut
@@ -970,6 +971,32 @@ def test_label_kfold():
970971
next, LabelKFold(n_folds=3).split(X, y, labels))
971972

972973

974+
def test_homogeneous_time_series_cv():
975+
X2 = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14]]
976+
htscv = HomogeneousTimeSeriesCV(3)
977+
978+
# Manually check that Homogeneous Time Series CV preserves the data ordering on toy datasets
979+
splits = htscv.split(X2[:-1])
980+
train, test = next(splits)
981+
assert_array_equal(train, [0, 1])
982+
assert_array_equal(test, [2, 3])
983+
984+
train, test = next(splits)
985+
assert_array_equal(train, [0, 1, 2, 3])
986+
assert_array_equal(test, [4, 5])
987+
988+
splits = HomogeneousTimeSeriesCV(3).split(X2)
989+
train, test = next(splits)
990+
assert_array_equal(train, [0, 1, 2])
991+
assert_array_equal(test, [3, 4])
992+
993+
train, test = next(splits)
994+
assert_array_equal(train, [0, 1, 2, 3, 4])
995+
assert_array_equal(test, [5, 6])
996+
997+
# Check get_n_splits returns the number of folds - 1
998+
assert_equal(2, htscv.get_n_splits())
999+
9731000
def test_nested_cv():
9741001
# Test if nested cross validation works with different combinations of cv
9751002
rng = np.random.RandomState(0)

0 commit comments

Comments
 (0)
0