Time series forecast using SVM?

3

I have a pandas data frame like this:

(index) 0           sie

0       1997-01-01  11.2
1        1997-01-03  12.3
2        1997-01-04  11.5
...
12454    2017-02-01  13.2

I would like to use SVM to predict the future values of the sie. How can I implement python code to predict these values?

I am doing something like this:

model = svm.SVR().fit(df[0],df['sie'])

But it is giving me this error:

ValueError: Found input variables with inconsistent numbers of samples: [1, 12455]

Although both df[0]anddf['sie'] have same shape of (12455,)

Note: I don't have continuous data (some dates, in between, are missing), also values in 0 are datetime.date() objects.

vizakshat

Posted 2017-06-14T12:24:38.110

Reputation: 411

Try this model = svm.SVR().fit(df['0'],df['sie']) – Grasshopper – 2017-06-14T12:49:48.187

Giving KeyError: '0'. I don't think this is a problem though.. – vizakshat – 2017-06-14T12:52:16.967

I used df.rename(columns={0:'Dates'}, inplace=True) and model = svm.SVR().fit(df['Dates'],df['sie']) still giving me **ValueError** – vizakshat – 2017-06-14T12:59:05.037

Answers

4

Here, a very good article: http://machinelearningmastery.com/time-series-forecasting-supervised-learning/

In a few words, define a window of size n and that is the size of your feature vector. Reshape the dataset and play.

pgalilea

Posted 2017-06-14T12:24:38.110

Reputation: 454

Actually I did not used sliding window method and trained my model. That was a disastrous mistake. The model trained well for the training time with X as the time feature :-P but predicted kinda average value for future times. Sliding window actually converts the time series into a supervised learning problem. \Thanks. – vizakshat – 2017-06-15T07:57:12.293

1

I used to solve the value error: model = svm.SVR().fit(np.transpose(np.matrix(df['Dates'])),np.transpose(np.matrix(df['sie'])))

More Info: https://stackoverflow.com/questions/30813044/sklearn-found-arrays-with-inconsistent-numbers-of-samples-when-calling-linearre

vizakshat

Posted 2017-06-14T12:24:38.110

Reputation: 411