# LibSVM and matlab for time series prediction

I have a problem making time series predictions with SVM and Matlab. I tried to solve the problem by myself in several ways without success.

I downloaded, compiled and installed LibSVM scripts for Matlab. But I don't know how to format my data in input. I mean, I have a time series that is an array of values, something like:

x=[1 2 3 4 5 6 7 8 9 10]


I want to use 70% of the vector as a training sequence of the SVM:

x1=[1 2 3 4 5 6 7]


Then I have to predict the last three values of the time series and I have to calculate the error between predicted values and the array [8 9 10].

I have to understand:

1. How to set SVM parameters. But there is a script that I found here that is the Matlab version of easy.py. So problem solved.

2. How to format my time series in order to be "acceptable" with easy.py (easy.m), svmtrain and svmpredict.

On LibSVM FAQ website I found this procedure [code]:

matlab> SPECTF = csvread('SPECTF.train'); % read a csv file
matlab> labels = SPECTF(:, 1); % labels from the 1st column
matlab> features = SPECTF(:, 2:end);
matlab> features_sparse = sparse(features); % features must be in a sparse matrix
matlab> libsvmwrite('SPECTFlibsvm.train', labels, features_sparse);


But I think this is a procedure for classification. From my point of view, how do I distinguish labels and features if I have only a simple array of values?

Here I found a similar procedure, but it is not clear if the script really works or not (I obtain a translated version of the input)

Can anyone help me?

-
 Uhm, not enough information. If you really only have feature vector, you won't get much of a prediction. Unless the later input to the classifier is exactly what you trained it with. In this case an SVM is overkill, just check for the known sequence. In any other case you'll at least want some negative examples. And why an SVM? It seems you want to map to multidimensional data. I'm not aware of a proven method to even do that with an SVM. What data do have and what do you expect? – Christian Mar 7 at 19:50

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);

-
Welcome to the site, @AhmedH.Radhwan. Would you mind adding some peripheral information to situate / motivate / explain your code? Since you're new here, you may want to read our about page & our FAQ, which contain info about CV. – gung Feb 5 at 17:05