Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: TimeSeries Forecasting Weka - Java API

  1. #1
    Join Date
    Mar 2017
    Posts
    2

    Default TimeSeries Forecasting Weka - Java API

    Hello,

    i am trying to implement TimeSeries Forecasting in a JavaService in webMethods. It seems that my Code is not working and i am completely lost so i would be glad if you could help me!

    This is the Exception i get: com.wm.lang.flow.FlowException: weka.core.expressionlanguage.parser.Parser.getSymbolFactory()Ljava_cup/runtime/SymbolFactory;
    I am not sure how webMethods specific this is. If it is you might not be able to help. But first let me show you my Code:

    I just post the part which is not webMethods specific (normal Java):

    In the first part i am building an ARFF File which works fine. Because i saved the file and opened it with the weka Explorer and everything works fine.

    The ARFF file looks like this:

    Code:
    @relation Rel
    
    
    @attribute Count numeric
    
    
    @data
    2758
    2797
    2861
    575
    505
    4029
    (just with some more values (28 in total))

    Forecasting Part:

    Code:
    // At the berginning i create and save the arff file, so i have an Instances object called 'dataset'
    
    WekaForecaster forecaster = new WekaForecaster();
    try {
        forecaster.setFieldsToForecast("Count");
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
    forecaster.setBaseForecaster(new GaussianProcesses());
    forecaster.getTSLagMaker().setTimeStampField("Date");
    forecaster.getTSLagMaker().setMinLag(1);
    forecaster.getTSLagMaker().setMaxLag(12);
    forecaster.getTSLagMaker().setAddMonthOfYear(true);
    forecaster.getTSLagMaker().setAddQuarterOfYear(true);
                    
    PrintStream stream = null;
    List<List<NumericPrediction>> forecast = null;
            
    try {            
          stream = new PrintStream("./path/forecast.txt");
          forecaster.buildForecaster(dataset, stream);
          forecaster.primeForecaster(dataset);
          forecast = forecaster.forecast(3, dataset, stream);        
    } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
    }
            
    // output the predictions
    for (int i = 0; i < 3; i++) {
          List<NumericPrediction> predsAtStep = forecast.get(i);
           NumericPrediction predForTarget = predsAtStep.get(0);
           stream.print("" + predForTarget.predicted() + " ");
           stream.println();
    }
    What am i missing?

  2. #2
    Join Date
    Aug 2006
    Posts
    1,741

    Default

    It looks like your data does not contain a date field, so you can't set a time stamp field to use. The forecasting system can generate an artificial timestamp for you, so remove forecaster.getTSLagMaker().setTimeStampField("Date"). Similarly, as there is no timestamp you can't have date-derived attributes (such as month of the year or quarter) computed. With only 28 values in the series I would set the maximum lag to something smaller (try 3 or 6).

    You can also use any regression scheme in Weka. GaussianProcesses is used in the example, but you can try others, such as LinearRegression or SMOreg.

    Cheers,
    Mark.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.