Skip to content

TimeSeriesSplit and required minimum of n_splits #11893

@mloning

Description

@mloning

Description

TimeSeriesSplit.split() throws error for n_splits=1 even though in documentation it requires at least 1. Not sure if documentation needs to be updated or bug in TimeSeriesSplit?

Steps/Code to Reproduce

Example:

timeseries= np.arange(0,10)
tscv = TimeSeriesSplit(n_splits=1)
for train, test in tscv.split(timeseries):
    print(train, test)

Expected Results

No error is thrown. In the documentation it requires n_splits at least 1 (and not at least 2).

Actual Results

------------------------------------------------------------------------
ValueError                             Traceback (most recent call last)
 <ipython-input-180-b869ddb34868> in <module>()
      1 time = np.arange(0,10)
----> 2 tscv = TimeSeriesSplit(n_splits=1)
      3 for train, test in tscv.split(ts):
      4     print(train, test)
~/.conda/envs/egym/lib/python3.6/site-packages/sklearn/model_selection/_split.py in __init__(self, n_splits, max_train_size)
    725         super(TimeSeriesSplit, self).__init__(n_splits,
    726                                               shuffle=False,
--> 727                                               random_state=None)
    728         self.max_train_size = max_train_size
    729 
~/.conda/envs/egym/lib/python3.6/site-packages/sklearn/model_selection/_split.py in __init__(self, n_splits, shuffle, random_state)
    282                 "k-fold cross-validation requires at least one"
    283                 " train/test split by setting n_splits=2 or more,"
--> 284                 " got n_splits={0}.".format(n_splits))
    285 
    286         if not isinstance(shuffle, bool):
ValueError: k-fold cross-validation requires at least one train/test split by setting n_splits=2 or more, got n_splits=1.

Versions

Linux-3.10.0-693.2.2.el7.x86_64-x86_64-with-centos-7.4.1708-Core
Python 3.6.5 | packaged by conda-forge | (default, Apr 6 2018, 13:39:56)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]
NumPy 1.14.3
SciPy 1.1.0
Scikit-Learn 0.19.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions