# How to put data in time series regression

I tried to get a result in regression on LIBSVM, and I get the same problem on single feature data or multivariate data.

Suppose I try to find the price of something, and I have the data for $N$ days. I give the day ($1,2,\ldots,N-1$) price for $X$ as independent variables, and I train it with the day ($2,3,\ldots,N$) price as the dependent variable. So I try to get the next day's price always.

When I get the solution ($Y$) on test data, surely I expect the data price for the days ($2 \ldots N$ for the test data). But I realized that the $Y$ values are always seems like the X values. When comparing the solution $Y$ with $X$ values, ($1,2,\ldots,N-1$) days, results are more successful than ($2,3,\ldots,N$) days.

In other words I expect the next days values but the result is more successful on the same day again.

What is wrong with the approach?

I believe this has been answered on a related site, Stack Overflow. The bottom line is that your data isn't structured to reflect a time series.

EDIT:

One question would be why are you using an SVM to do regression? There may be methods better-suited to your data type. But assuming you have a reason for using SVM...

You were "predicting" the next value of Y based on the current value of X (which we'll assume are evenly-spaced values and don't really matter per-se). Instead, you need to predict the next value of Y based on the latest K values of Y. (Experiment with different K.)

For example, say you decide to predict a day's value based on the values of the previous two weeks (14 days). In that case, if you are predicting day 29, you'd use the values of days 15..28, and if you are predicting day 30, you'd use the values of days 16..29, and so on.

The training set x is thus a vector of vectors of length 14: Day 1..Day 14, Day 2..Day 15, etc. And the training set y is thus a vector of scalars: Day 15, Day 16, etc.

• I have the same problem that's it. But i didn't understand the answer x[0]=Y[0:K]; y[0]=Y[K] x[1]=Y[1:K+1]; y[1]=[K+1] – user2602256 Aug 27 '13 at 23:03
• In what structure should I use for my data? – user2602256 Aug 27 '13 at 23:09
• Actually i use regression on Libsvm, I editted again as regression. I also used this aprroach not for 14 days but for 3 days like: X (day 1 )....... X(day 2)......... X (day 3)........ Y(day 4)::::: X (day 2)........ X(day 3)......... X (day 4)........ Y(day 5)::::: X (day 3)........ X(day 4)......... X (day 5)........ Y(day 6)::::: … … … X (day 48)....... X(day 49)........ X(day 50)........ Y(day 51) But the output Y (day 4,5…51) fitted the last X vector (day 3,4…50) this time. Is that the same approach with yours? – user2602256 Aug 27 '13 at 23:40