title: WEKA Forecasting Plugin
body: <p>My question is related to Weka <a href="http://wiki.pentaho.com/display/DATAMINING/Using+the+Weka+Forecasting+Plugin" rel="nofollow noreferrer">Forecasting Plugin</a>. 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?</p>
  
  <p>I made sure to use the same "options" of the algorithm but still results are different.</p>
  
  <p>Here's the code:</p>
  
  <pre class="lang-java prettyprint-override"><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 &lt;= 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&lt;List&lt;NumericPrediction&gt;&gt; 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();
          }
      }
  }
  </code></pre>