1
$\begingroup$

I would like to train my model with a validation set. As the data is a time series I have to use timeseriessplit:

import numpy as np    
from sklearn.model_selection import TimeSeriesSplit   
X = np.array([[1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4]])    
y = np.array([1, 2, 3, 4, 5, 6])    
tscv = TimeSeriesSplit(n_splits=5)    
print(tscv)      
TimeSeriesSplit(max_train_size=None, n_splits=5)    
for train_index, test_index in tscv.split(X):    
...    print("TRAIN:", train_index, "TEST:", test_index)    
...    X_train, X_test = X[train_index], X[test_index]    
...    y_train, y_test = y[train_index], y[test_index]    
TRAIN: [0] TEST: [1]    
TRAIN: [0 1] TEST: [2]    
TRAIN: [0 1 2] TEST: [3]    
TRAIN: [0 1 2 3] TEST: [4]    
TRAIN: [0 1 2 3 4] TEST: [5]

Using this method, I obtain a train and test set. But how can I generate a validation set now?

$\endgroup$
1
$\begingroup$

Im new to the topic too but I think the Idea is to create a Train/Test-Set and then take the TrainSet and Split it again in 2 Sets (mostly called Train and Development Set) for example with a KFold-CV. Train your model on the Train Set and improve it with the Developement Set. Then take the final model and use it on the whole trainingset.

The picture give you a clearer idea I think. enter image description here

$\endgroup$
2
  • $\begingroup$ The validation set is typically constructed by dividing the train set accordingly, yes. But again with TimeSeriesSplit? I loose a bit the overview when performing this twice, that's why I am rather unsure how to proceed. $\endgroup$
    – Ben
    Oct 2 '19 at 13:00
  • 1
    $\begingroup$ Well as I said, unfortunatly I am pretty new too... I will watch out for someone to explain it. $\endgroup$
    – CRoNiC
    Oct 2 '19 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.