0

I have a time series like:

index date id value
0     d1   a  10
1     d2   a  15
2     d2   b  20
3     d3   a  18
4     d3   b  19
5     d4   b  21
6     d4   c  25

I want to do a time series split, so the splits would be:

train_1 = index[0], test_1 = index[1, 2]
train_2 = index[0, 1, 2], test_2 = index[3, 4]

and so on...

Is there a simple way so I can implement on a cross-validation, like:

for train_idx, test_idx in split_indexes:
    model.fit(X.iloc[train_idx], y_tr.iloc[train_idx])
    ...
  • What are your constraints? Do the training rows need to come before the test rows? Should each segment be contiguous? Does the training segment always include the first row? – Ben Grossmann Jun 26 '23 at 21:18
  • In each split the training fold is basically the last training + test folds, while the test fold is the next n periods. – Fernando Quintino Jun 26 '23 at 21:55

0 Answers0