Add rolling window to sklearn.model_selection.TimeSeriesSplit

### Describe the workflow you want to enable

I wanted to ask whether any plans exist to implement a rolling/sliding window method in the TimeSeriesSplit class:

![68747470733a2f2f692e6962622e636f2f4b576b665137712f6e6577706c6f742e706e67](https://user-images.githubusercontent.com/28893120/154545460-d1629e8a-22a4-494d-affc-2df3cb95ade7.png)

 Currently, we are limited to using the expanding window type. For many financial time series models where a feature experiences a structural break, having a model whose weights are trained on the entire history can prove suboptimal.

I noted in https://github.com/scikit-learn/scikit-learn/pull/13204, specifically svenstehle's comments, that this might be on the horizon? 

### Describe your proposed solution

Current Implementation

```
>>> x = np.arange(15)
>>> cv = TimeSeriesSplit(n_splits=3, gap=2)
>>> for train_index, test_index in cv.split(x):
...      print("TRAIN:", train_index, "TEST:", test_index)
TRAIN: [0 1 2 3] TEST: [6 7 8]
TRAIN: [0 1 2 3 4 5 6] TEST: [ 9 10 11]
TRAIN: [0 1 2 3 4 5 6 7 8 9] TEST: [12 13 14]
```

Desired outcome

```
>>> x = np.arange(10)
>>> cv = TimeSeriesSplit(n_splits='walk_fw',  max_train_size=3, max_test_size=1)
>>> for train_index, test_index in cv.split(x):
...      print("TRAIN:", train_index, "TEST:", test_index)
TRAIN: [0 1 2] TEST: [3]
TRAIN: [1 2 3] TEST: [ 4]
TRAIN: [2 3 4] TEST: [5]
TRAIN: [ 3 4 5] TEST: [6]
TRAIN: [ 4 5 6] TEST: [7]
TRAIN: [ 5 6 7] TEST: [8]
TRAIN: [ 6 7 8] TEST: [9]
```

Where the 'stride' of the walk forward is proportionate to the test set, or walks by the max_train_size parameter?



### Describe alternatives you've considered, if relevant

_No response_

### Additional context

_No response_

COMMENT:
Yes. Ideally, the `n_splits` parameter could be done away with?

Therefore, the implementation reduces to how many observations are used in
your rolling training window i.e. assuming daily observations, for a given
financial time series, you could train a model on a rolling 252 day
training window, and validate on a 63 day window, walking forward by the
validation size.










On Thu, Apr 14, 2022 at 2:24 PM Thomas J. Fan ***@***.***>
wrote:

> Currently there is rolling window support, where the train set does not
> grow:
>
> from sklearn.model_selection import TimeSeriesSplit
> x = np.arange(15)cv = TimeSeriesSplit(max_train_size=3, test_size=1)for train_index, test_index in cv.split(x):
>     print("TRAIN:", train_index, "TEST:", test_index)
> # TRAIN: [7 8 9] TEST: [10]# TRAIN: [ 8  9 10] TEST: [11]# TRAIN: [ 9 10 11] TEST: [12]# TRAIN: [10 11 12] TEST: [13]# TRAIN: [11 12 13] TEST: [14]
>
> If we want all the windows, we would need to adjust n_splits explicitly:
>
> from sklearn.model_selection import TimeSeriesSplit
> x = np.arange(15)cv = TimeSeriesSplit(n_splits=12, max_train_size=3 ,test_size=1)for train_index, test_index in cv.split(x):
>     print("TRAIN:", train_index, "TEST:", test_index)
> # TRAIN: [0 1 2] TEST: [3]# TRAIN: [1 2 3] TEST: [4]# TRAIN: [2 3 4] TEST: [5]# TRAIN: [3 4 5] TEST: [6]# TRAIN: [4 5 6] TEST: [7]# TRAIN: [5 6 7] TEST: [8]# TRAIN: [6 7 8] TEST: [9]# TRAIN: [7 8 9] TEST: [10]# TRAIN: [ 8  9 10] TEST: [11]# TRAIN: [ 9 10 11] TEST: [12]# TRAIN: [10 11 12] TEST: [13]# TRAIN: [11 12 13] TEST: [14]
>
> Is the proposal to have n_splits='walk_fw' provide all the windows
> automatically?
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/scikit-learn/scikit-learn/issues/22523#issuecomment-1099183543>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AG4N7QGCNNBIXSZYM2AM6YLVFAMCHANCNFSM5OVPUV5Q>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>

Labels: New Feature, module:model_selection