I have been trying to use Support Vector Machine method for time series forecasting. I have seen allot of research papers, but nobody shared the code or tool they have used for that. Got some materials from KU Leuven. " LS-SVMlab Toolbox User’s Guide version 1.7" using the code in the page 34 section 3.3.8."

The problem is it cannot predict accurately.

It would be great if anybody can share the code for the problem and the software for that.(Matlab/R etc).

Attaching here the Matlab output and code i have used.

% load time-series in X and Xt

lag = 50;

Xu = windowize(X,1:lag+1);

Xtra = Xu(1:end-lag,1:lag); %training set

Ytra = Xu(1:end-lag,end); %training set

Xs=X(end-lag+1:end,1); %starting point for iterative prediction Cross-validation is based upon feedforward simulation on the validation set using the feedforwardly trained model:

[gam,sig2] = tunelssvm({Xtra,Ytra,’f’,[],[],’RBF_kernel’},’simplex’,... ’crossvalidatelssvm’,{10,’mae’}); Prediction of the next 100 points is done in a recurrent way:

[alpha,b] = trainlssvm({Xtra,Ytra,’f’,gam,sig2,’RBF_kernel’});

%predict next 100 points

prediction = predict({Xtra,Ytra,’f’,gam,sig2,’RBF_kernel’},Xs,50);

plot([prediction Xs]);

enter image description here

  • $\begingroup$ Possible duplicate of this post. $\endgroup$
    – forecaster
    Mar 9, 2015 at 17:52

1 Answer 1


SVM's are particularly ill-suited for time prediction analysis due to stationarity assumptions. You can circumvent these restrictions by clever use of feature or kernel engineering essential rendering the data distribution stationary though. I'd suggest to take a look at ARIMA related literature & models to see some of the typical "terms" that are included.

Specifically, you could try incorporating:

  • Previous predictions (especially $x_{t-1}$)
  • Movement of the distribution (e.g. $(x_{t-1} - x_{t-2})/x_{t-1}$ or PID)
  • Trends (lagged previous averages, say a dummy for every weekday in intraday trading data)

The latter should easily solve your problem afaik.

  • $\begingroup$ Hi @ciri , how could it possible for the same time series is correct for the KU leaven and not for me using the same code, and same data in matlablink see page 34 section 3.3.8. See data source link $\endgroup$ Mar 12, 2015 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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