My question is related to Weka Forecasting Plugin. I'm trying to predict the value of sin(x) in a prediction horizon of 6 using Weka Forecaster, the algorithm is SMOReg, and I'm trying to use different lags ( 1 - 24 ). I'm using a loop for that. The program I wrote is working perfectly but the problem is the results I obtain from my program are different than using Weka GUI directly and I don't know why? Any ideas?
I made sure to use the same "options" of the algorithm but still results are different.
Here's the code:
import java.io.*;
import java.util.*;
import java.util.List;
import weka.core.Instances;
import weka.classifiers.Evaluation;
import weka.classifiers.functions.*;
import weka.classifiers.rules.*;
import weka.classifiers.meta.*;
import weka.classifiers.trees.*;
import weka.classifiers.evaluation.NumericPrediction;
import weka.classifiers.timeseries.WekaForecaster;
import weka.classifiers.timeseries.core.TSLagMaker;
import weka.classifiers.timeseries.core.TSLagMaker.Periodicity;
import weka.classifiers.timeseries.eval.TSEvaluation;
import weka.classifiers.timeseries.eval.ErrorModule;
import weka.core.converters.ConverterUtils.DataSource;
public class TimeSeriesSin {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) throws FileNotFoundException{
try {
String pathToSinData = "C:/Users/khouloud/Desktop/AUSmaster/thesis/summer/chapter1/sin_10.arff";
PrintWriter out = new PrintWriter("C:/Users/khouloud/Desktop/AUSmaster/thesis/summer/chapter1/try_sin_10.txt");
DataSource source = new DataSource(pathToSinData);
Instances diab = source.getDataSet();
for(int i = 1; i <= 24; i++) {
WekaForecaster forecaster = new WekaForecaster();
forecaster.setFieldsToForecast("sin");
SMOreg tr = new SMOreg();
String options = "weka.classifiers.functions.SMOreg -C 1.0 -N 0 -I \"weka.classifiers.functions.supportVector.RegSMOImproved -L 0.001 -W 1 -P 1.0E-12 -T 0.001 -V\" -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\"";
tr.setOptions(weka.core.Utils.splitOptions(options));
forecaster.setBaseForecaster(tr);
forecaster.getTSLagMaker().setMinLag(1);
forecaster.getTSLagMaker().setMaxLag(i);
forecaster.buildForecaster(diab, System.out);
forecaster.primeForecaster(diab);
List<List<NumericPrediction>> forecast = forecaster.forecast(6, System.out);
TSEvaluation eval = new TSEvaluation(diab, 0.3);
eval.setHorizon(6);
eval.setEvaluateOnTestData(true);
eval.setEvaluateOnTrainingData(false);
eval.evaluateForecaster(forecaster, System.out);
out.println("lag= " + i);
out.println(eval.toSummaryString());
}
out.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I got the same problem for forecasting three different variables. I used MLPRegressor
and SMOreg
.
I checked the package version of the pdm-timseriesforecasting
package from WEKA-GUI
in the Package Manager and put the same package versions in my WEKA-code (I was using a maven repository for my code implementation) and the problem was solved.