Posts

Showing posts with the label cross-validation

Sklearn : Get last split from timeSeriesSplit

Sklearn : Get last split from timeSeriesSplit So I am using the timeSeriesSplit from sklearn to split my data like this, tscv = TimeSeriesSplit(n_splits=3) Now I know in order to get the split indices we have to iterate over tscv.split(X) . My question here is, is it possible to get directly to the last split, without iterating over the splits. The object returned by the function is not exactly a list, so I am not sure how to do this ? I need the last split only, since my data is large and no. of splits is also large. tscv.split(X) Thanks in advance 2 Answers 2 You can try this def get_last_cv(splits): splits_deque = deque(splits, maxlen=1) last_element = splits_deque.pop() train,test = last_element return train,test and then get the indices like this train_index,test_index = get_last_cv(tscv.split(X)) where X is your data X Split method in TimeSeriesSplit generates split of indi...