简体   繁体   中英

Lag in time series regression using LibSVM

I use libSVM in Matlab to examine the utility of SVM regression for time series prediction. I use the following code sample:

t = -10:0.1:10;
x = 2*sin(10*t)+0.5*t.^2+4;
x = (x - min(x)) / (max(x) - min(x));
x = x';
data              = x(1:end-1);
dataLabels        = x(2:end);
trainDataLength   = round(length(data)*70/100);
TrainingSet       = data(1:trainDataLength);
TrainingSetLabels = dataLabels(1:trainDataLength);
TestSet           = data(trainDataLength+1:end);
TestSetLabels     = dataLabels(trainDataLength+1:end);

options = ' -s 3 -t 2 -c 100 -p 0.001 -h 0';
model   = svmtrain(TrainingSetLabels, TrainingSet, options);

[predicted_label, accuracy, decision_values] = svmpredict(TestSetLabels, TestSet, model);

figure(2);
plot(1:length(TestSetLabels), TestSetLabels, '-b');
hold on;
plot(1:length(TestSetLabels), predicted_label, '-r');
hold off;

and the figure I get is:

在此处输入图片说明

from the figure it can be seen that there is a lag in predicted values vs. actual values. I don't know if this lag is because of some bug in my code, in libSVM code, or that it is natural, and we cannot expect to predict one-step ahead value of the time series.

What you do in this line

model   = svmtrain(TrainingSetLabels, TrainingSet, options);

Is to ask to estimate y=TrainingSetLabels with the features contained in x=TrainingSet.

Given your code, there is a one timestep lag between x and y, so the behavior is normal. However, you can improve your estimation. x can be a matrix, with one column per feature vector. What can do is to add the following columns :

  • x with one time step lag (you already have it)
  • x with N time steps lag (where N corresponds to the period of your sinus)
  • a column vector such as (1:1:length(x)), which will be used to estimate your trend.

This way (mostly with the N time step lag column), you will be able to really anticipate the incoming values.

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM