Predicting time series with scikit learn

I am a complete newbie in SVM-based forecasting and therefore look for some recommendations here. I am trying to configure python code to predict time series using scikit-learn SVM libraries.

My data contains X values ​​at 30-minute intervals in the last 24 hours, and I need to predict y for the next timestamp. Here is what I installed -

SVR(kernel='linear', C=1e3).fit(X, y).predict(X) 

But for this prediction to work, I need an X value for the next timestamp, which is not available. How to configure this to predict future y values?

+5
source share
1 answer

You should use SVR as follows:

 # prepare model and set parameters svr_model = SVR(kernel='linear', C=1e3) # fit your model with the training set svr_model.fit(TRAINIG_SET, TAINING_LABEL) #predict on a test set svr_model.predict(TEST_SET) 

So, the problem is that you have a training kit, but not a test suite to measure your model accuracy. The only solution is to use part of your training set as an ex: 80% for train 20% for test test suite ex: 80% for train 20% for test

EDIT

I hope I understand well what you want from your comments.

So, you want to predict the next label in the last hour in your train set, here is an example of what you want:

 from sklearn.svm import SVR import random import numpy as np ''' data: the train set, 24 elements label: label for each time ''' data = [10+y for y in [x * .5 for x in range(24)]] label = [z for z in [random.random()]*24] # reshaping the train set and the label ... DATA = np.array([data]).T LABEL = np.array(label) # Declaring model and fitting it clf = SVR(kernel='linear', C=1e3) clf.fit(DATA, LABEL) # predict the next label to_predict = DATA[DATA[23,0]+0.5] print clf.predict(to_predict) >> 0.94407674 
+3
source

All Articles