You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to forecast univariate time series (my data is composed by two columns, a timestamp and a numeric value) using epsilon-SVR from LIBSVM in Java.
When I do not use features, considering only the array index as feature (which I know it is not trustworthy) it returns always the same value. If I use a sliding window, i.e, the features to predict the value at time t are the values at time t-1,t-2,..., t-sliding_window, it always returns NaN.
I do as above to train the model:
`public svm_model train(double[] series, int svmType, int kernelType, int degree, double gamma, double coef0, double C, double eps, double p, int shrinking, int nFeatures)
{
series = normalize(series)
svm_parameter params = new svm_parameter();
svm_problem problem = new svm_problem();
svm_node node = null;
//----------Set parameters----------
params.svm_type = svmType;
params.kernel_type = kernelType;
params.degree = degree;
params.gamma = 1/nFeatures;
params.coef0 = coef0;
params.C = C;
params.eps = eps;
params.cache_size=100;
params.p = p;
params.shrinking= shrinking;
//----------Define problem----------
problem.l = series.length;
problem.y = series;
problem.x = new svm_node[series.length][];
for(int i=0;i<series.length;i++)
{
problem.x[i] = new svm_node[1];
node = new svm_node();
node.index = 0;
node.value = i;
problem.x[i][0] = node;
}
//----------Generate model----------
svm_model svm_model = svm.svm_train(problem,params);
return svm_model;
}
public svm_model trainSlidingWindow(double[] series, int svmType, int kernelType, int degree, double gamma, double coef0, double C, double eps, double p, int shrinking, int nFeatures, int slidingWindow)
{
series = normalize(series)
svm_parameter params = new svm_parameter();
svm_problem problem = new svm_problem();
svm_node node = null;
//----------Set parameters----------
params.svm_type = svmType;
params.kernel_type = kernelType;
params.degree = degree;
params.gamma = 1/nFeatures;
params.coef0 = coef0;
params.C = c;
params.eps = eps;
params.cache_size=100;
params.p=p;
params.shrinking= shrinking;
//----------Define problem----------
problem.l = series.length;
problem.y = series;
problem.x = new svm_node[series.length][slidingWindow];
for(int i=0;i<series.length;i++)
{
problem.x[i] = new svm_node[slidingWindow];
for(int j=0; j<slidingWindow;j++)
{
node = new svm_node();
node.index = slidingWindow-(j+1);
if(i-(j+1) <0)
node.value = Double.NaN;
else
node.value = series[i-(j+1)];
problem.x[i][j] = node;
}
}
//----------Generate model----------
svm_model svm_model = svm.svm_train(problem,params);
return svm_model;
}`
The forecasts are obtained as follows:
`public double[] predict(double[] series, svm_model model, int steps)
{
series = normalize(series);
double[] yPred = new double[steps];
for(int i=0;i<steps;i++)
{
svm_node[] nodes = new svm_node[1];
svm_node node = new svm_node();
node.index = 0;
node.value = series.length + i;
nodes[0] = node;
yPred[i] = svm.svm_predict(model,nodes);
}
return denormalize(yPred);
}
public double[] predictSlidingWindow(double[] series, svm_model model, int steps, int slidingWindow)
{
series = normalize(series);
double[] yPred = new double[steps];
double[] aux = new double[slidingWindow+steps];
System.arraycopy(series,series.length-slidingWindow,aux,0, slidingWindow);
for(int i=0;i<steps;i++)
{
svm_node[] nodes = new svm_node[slidingWindow];
for(int j=0;j<slidingWindow;j++)
{
svm_node node = new svm_node();
node.index = slidingWindow-(j+1);
node.value = aux[i+j];
nodes[j] = node;
}
yPred[i] = svm.svm_predict(model,nodes);
aux[slidingWindow+i] = yPred[i];
}
return denormalize(yPred);
}`
The text was updated successfully, but these errors were encountered:
I am trying to forecast univariate time series (my data is composed by two columns, a timestamp and a numeric value) using epsilon-SVR from LIBSVM in Java.
When I do not use features, considering only the array index as feature (which I know it is not trustworthy) it returns always the same value. If I use a sliding window, i.e, the features to predict the value at time t are the values at time t-1,t-2,..., t-sliding_window, it always returns NaN.
I do as above to train the model:
`public svm_model train(double[] series, int svmType, int kernelType, int degree, double gamma, double coef0, double C, double eps, double p, int shrinking, int nFeatures)
{
series = normalize(series)
svm_parameter params = new svm_parameter();
svm_problem problem = new svm_problem();
svm_node node = null;
//----------Set parameters----------
params.svm_type = svmType;
params.kernel_type = kernelType;
params.degree = degree;
params.gamma = 1/nFeatures;
params.coef0 = coef0;
params.C = C;
params.eps = eps;
params.cache_size=100;
params.p = p;
params.shrinking= shrinking;
//----------Define problem----------
problem.l = series.length;
problem.y = series;
problem.x = new svm_node[series.length][];
for(int i=0;i<series.length;i++)
{
problem.x[i] = new svm_node[1];
node = new svm_node();
node.index = 0;
node.value = i;
problem.x[i][0] = node;
}
//----------Generate model----------
svm_model svm_model = svm.svm_train(problem,params);
return svm_model;
}
public svm_model trainSlidingWindow(double[] series, int svmType, int kernelType, int degree, double gamma, double coef0, double C, double eps, double p, int shrinking, int nFeatures, int slidingWindow)
{
series = normalize(series)
svm_parameter params = new svm_parameter();
svm_problem problem = new svm_problem();
svm_node node = null;
//----------Set parameters----------
params.svm_type = svmType;
params.kernel_type = kernelType;
params.degree = degree;
params.gamma = 1/nFeatures;
params.coef0 = coef0;
params.C = c;
params.eps = eps;
params.cache_size=100;
params.p=p;
params.shrinking= shrinking;
//----------Define problem----------
problem.l = series.length;
problem.y = series;
problem.x = new svm_node[series.length][slidingWindow];
for(int i=0;i<series.length;i++)
{
problem.x[i] = new svm_node[slidingWindow];
for(int j=0; j<slidingWindow;j++)
{
node = new svm_node();
node.index = slidingWindow-(j+1);
if(i-(j+1) <0)
node.value = Double.NaN;
else
node.value = series[i-(j+1)];
problem.x[i][j] = node;
}
}
//----------Generate model----------
svm_model svm_model = svm.svm_train(problem,params);
return svm_model;
}`
The forecasts are obtained as follows:
`public double[] predict(double[] series, svm_model model, int steps)
{
series = normalize(series);
double[] yPred = new double[steps];
for(int i=0;i<steps;i++)
{
svm_node[] nodes = new svm_node[1];
svm_node node = new svm_node();
node.index = 0;
node.value = series.length + i;
nodes[0] = node;
yPred[i] = svm.svm_predict(model,nodes);
}
return denormalize(yPred);
}
public double[] predictSlidingWindow(double[] series, svm_model model, int steps, int slidingWindow)
{
series = normalize(series);
double[] yPred = new double[steps];
double[] aux = new double[slidingWindow+steps];
System.arraycopy(series,series.length-slidingWindow,aux,0, slidingWindow);
for(int i=0;i<steps;i++)
{
svm_node[] nodes = new svm_node[slidingWindow];
for(int j=0;j<slidingWindow;j++)
{
svm_node node = new svm_node();
node.index = slidingWindow-(j+1);
node.value = aux[i+j];
nodes[j] = node;
}
yPred[i] = svm.svm_predict(model,nodes);
aux[slidingWindow+i] = yPred[i];
}
return denormalize(yPred);
}`
The text was updated successfully, but these errors were encountered: