Incorrect prediction using svmtrain/svmpredict
9 views (last 30 days)
Show older comments
Dear all,
I've been using the libsvm package to predict a timeseries (regression analysis using SVM). The code I've used is below:
***
A = csvread('norm agv BDI.csv');
% generate sin function points with period of 5 years (60 months)
A(:,3) = sin(A(:,2)*2*pi/60);
% normalize values from [-1,1] to [0,1]
A(:,3) = (A(:,3)+1)./2;
plot(A(1:360,2),A(1:360,3),'or');
hold on
% denoise data:
xd = wden(A(:,3)','heursure','s','one',3,'db3')';
plot(A(1:360,2),xd(1:360),'-b','LineWidth',5);
trainfeatures = [A(:,2)];
model = svmtrain(xd(1:336), trainfeatures(1:336,:), '-s 4 -t 2 -c 5.5 -e 0.02');
% options are:
% -s SVM type: 3 - epsilon SVR, 4 - nuSVR
% -t kernel type: 2 radial basis function: exp(-gamma*|u-v|^2)
% -c cost (value of parameter C)
% -e epsilon: tolerance of termination criterion
[predicted_label] = svmpredict(xd, trainfeatures, model);
[A(:,2), predicted_label, xd]
% now overlay the predicted model
plot(A(:,2),predicted_label,'-g','LineWidth',2);
The first two columns of vector A are read from a file which starts like this:
31533.00,0,-0.932541478
31564.00,1,-0.935964688
31594.00,2,-0.949384932
31625.00,3,-0.946143266
31656.00,4,-0.916051242
31686.00,5,-0.908048373
31717.00,6,-0.911407848
31747.00,7,-0.924103013
31778.00,8,-0.905556669
31809.00,9,-0.895828641
...
First column is day number (never used), second column is month, last column is timeseries value for the corresponding month.Ignore for now the denoising bit, that is there for another timeseries that requires it, for now I am just testing the code using a sine function rescaled from 0 to 1.
I am using all the 360-month data, except for the last 24 months, to generate an SVM model using svmtrain. Then I am feeding this model in svmpredict to get everything (including the last 24 months). As you can see in the figure below, I am getting excellent agreement on the training set (red - original data, blue - denoised, green - predicted), but as I look at the last 24 months I get a flat green line. I tried playing around with the C and epsilon parameters but got same results regardless of their values.
Any idea what might be wrong here?
Cristian

0 Comments
Answers (0)
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!