Scikit 中还提供了专门用于时间序列模型的交叉验证器。
In [1]: from sklearn.model_selection import TimeSeriesSplit
In [2]: X = ["a", "b", "c", "d", "e", "f"]
In [3]: y = [0, 0, 1, 1, 1, 1,]
In [4]: tscv = TimeSeriesSplit(n_splits=3)
In [5]: for train, test in tscv.split(X):
...: print("%s-%s" % (train, test))
[0 1 2]-[3]
[0 1 2 3]-[4]
[0 1 2 3 4]-[5]