Example usage for weka.classifiers.timeseries WekaForecaster WekaForecaster

List of usage examples for weka.classifiers.timeseries WekaForecaster WekaForecaster

Introduction

In this page you can find the example usage for weka.classifiers.timeseries WekaForecaster WekaForecaster.

Prototype

WekaForecaster

Source Link

Usage

From source file:adams.flow.container.WekaForecastContainer.java

License:Open Source License

/**
 * Initializes the container.//from  w w  w .j a va 2s  .co m
 * <br><br>
 * Only used for generating help information.
 */
public WekaForecastContainer() {
    this(new WekaForecaster(), new ArrayList<List<NumericPrediction>>());
}

From source file:crystalball.quant.QuantWekaSMOreg.java

License:Open Source License

public void forecast(BarData barData, int startBarId, int endBarId) {
    makeDataSet(barData, startBarId, endBarId);
    try {/*w  w w . ja v  a  2s.c  om*/
        if (isLastBarOfHalfHour(barData, endBarId) || forecaster == null) {
            // new forecaster
            forecaster = new WekaForecaster();

            // set the targets we want to forecast. This method calls
            // setFieldsToLag() on the lag maker object for us
            forecaster.setFieldsToForecast("close");

            // set the underlying classifier as SMOreg (SVM)
            forecaster.setBaseForecaster(new SMOreg());

            forecaster.getTSLagMaker().setTimeStampField("id"); // date time stamp
            forecaster.getTSLagMaker().setMinLag(1);
            forecaster.getTSLagMaker().setMaxLag(78);

            // add a month of the year indicator field
            forecaster.getTSLagMaker().setAddMonthOfYear(false);

            // add a quarter of the year indicator field
            forecaster.getTSLagMaker().setAddQuarterOfYear(false);

            // build the model
            forecaster.buildForecaster(instances);
        }

        // prime the forecaster with enough recent historical data
        // to cover up to the maximum lag. 
        forecaster.primeForecaster(instances);

        // forecast for 6 units beyond the end of the training data
        List<List<NumericPrediction>> forecast = forecaster.forecast(predictSteps, System.out);

        // output the predictions. Outer list is over the steps; inner list is over
        // the targets
        for (int i = 0; i < predictSteps; i++) {
            List<NumericPrediction> predsAtStep = forecast.get(i);
            for (int j = 0; j < 1; j++) {
                NumericPrediction predForTarget = predsAtStep.get(j);
                predicted[i] = predForTarget.predicted();
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:org.datahack.forecast.BayExample.java

public static void main(String[] args) {
    try {/*w w  w.ja va2  s . c  o m*/
        // path to the Australian wine data included with the time series forecasting
        // package

        File output = File.createTempFile("tempWineData", "arff");
        output.deleteOnExit();
        String dataFileName = "sample-data/wine.arff";
        URL resource = BayExample.class.getResource("/" + dataFileName);
        FileUtils.copyURLToFile(resource, output);

        String pathToWineData = output.getPath();

        // load the wine data
        Instances wine = new Instances(new BufferedReader(new FileReader(pathToWineData)));

        InstanceQuery q = new InstanceQuery();

        // new forecaster
        WekaForecaster forecaster = new WekaForecaster();

        // set the targets we want to forecast. This method calls
        // setFieldsToLag() on the lag maker object for us
        forecaster.setFieldsToForecast("Fortified,Dry-white");

        // default underlying classifier is SMOreg (SVM) - we'll use
        // gaussian processes for regression instead
        forecaster.setBaseForecaster(new GaussianProcesses());

        forecaster.getTSLagMaker().setTimeStampField("Date"); // date time stamp
        forecaster.getTSLagMaker().setMinLag(1);
        forecaster.getTSLagMaker().setMaxLag(12); // monthly data

        // add a month of the year indicator field
        forecaster.getTSLagMaker().setAddMonthOfYear(true);

        // add a quarter of the year indicator field
        forecaster.getTSLagMaker().setAddQuarterOfYear(true);

        // build the model
        forecaster.buildForecaster(wine, System.out);

        // prime the forecaster with enough recent historical data
        // to cover up to the maximum lag. In our case, we could just supply
        // the 12 most recent historical instances, as this covers our maximum
        // lag period
        forecaster.primeForecaster(wine);

        // forecast for 12 units (months) beyond the end of the
        // training data
        List<List<NumericPrediction>> forecast = forecaster.forecast(12, System.out);

        // output the predictions. Outer list is over the steps; inner list is over
        // the targets
        for (int i = 0; i < 12; i++) {
            List<NumericPrediction> predsAtStep = forecast.get(i);
            for (int j = 0; j < 2; j++) {
                NumericPrediction predForTarget = predsAtStep.get(j);
                System.out.print("" + predForTarget.predicted() + " ");
            }
            System.out.println();
        }

        // we can continue to use the trained forecaster for further forecasting
        // by priming with the most recent historical data (as it becomes available).
        // At some stage it becomes prudent to re-build the model using current
        // historical data.

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:org.datahack.forecast.TimeSeriesExample.java

public static void main(String[] args) {
    try {//  w  w  w .ja  v a2  s  .c o  m
        // path to the Australian wine data included with the time series forecasting
        // package

        File output = File.createTempFile("tempWineData", "arff");
        output.deleteOnExit();
        String dataFileName = "sample-data/parking344.arff";
        URL resource = TimeSeriesExample.class.getResource("/" + dataFileName);
        FileUtils.copyURLToFile(resource, output);

        String pathToWineData = output.getPath();

        // load the wine data
        Instances wine = new Instances(new BufferedReader(new FileReader(pathToWineData)));

        // new forecaster
        WekaForecaster forecaster = new WekaForecaster();

        // set the targets we want to forecast. This method calls
        // setFieldsToLag() on the lag maker object for us
        forecaster.setFieldsToForecast("occupiedSpaces");

        // default underlying classifier is SMOreg (SVM) - we'll use
        // gaussian processes for regression instead
        forecaster.setBaseForecaster(new GaussianProcesses());

        forecaster.getTSLagMaker().setTimeStampField("eventTime"); // date time stamp
        forecaster.getTSLagMaker().setMinLag(1);
        forecaster.getTSLagMaker().setMaxLag(12); // monthly data

        // add a month of the year indicator field
        forecaster.getTSLagMaker().setAddMonthOfYear(true);

        // add a quarter of the year indicator field
        forecaster.getTSLagMaker().setAddQuarterOfYear(true);

        // build the model
        forecaster.buildForecaster(wine, System.out);

        // prime the forecaster with enough recent historical data
        // to cover up to the maximum lag. In our case, we could just supply
        // the 12 most recent historical instances, as this covers our maximum
        // lag period
        forecaster.primeForecaster(wine);

        // forecast for 12 units (months) beyond the end of the
        // training data
        List<List<NumericPrediction>> forecast = forecaster.forecast(12, System.out);

        // output the predictions. Outer list is over the steps; inner list is over
        // the targets
        for (int i = 0; i < 12; i++) {
            List<NumericPrediction> predsAtStep = forecast.get(i);
            for (int j = 0; j < 2; j++) {
                NumericPrediction predForTarget = predsAtStep.get(j);
                System.out.print("" + predForTarget.predicted() + " ");
            }
            System.out.println();
        }

        // we can continue to use the trained forecaster for further forecasting
        // by priming with the most recent historical data (as it becomes available).
        // At some stage it becomes prudent to re-build the model using current
        // historical data.

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Prediccion.PrecidePasoNodo.java

License:Open Source License

public PrecidePasoNodo(String fecha, String nodo) {
    this.fecha = fecha;
    this.nodo = nodo;

    forecaster = new WekaForecaster();

}

From source file:Prediccion.Prediccion.java

License:Open Source License

@Override
public void run() {
    try {//from   w ww . j a va 2s .c  om

        ArrayList<Instances> pasos = cargarDatos();

        System.err.println(pasos.size());

        //Instanciamos el predictor
        ArrayList<WekaForecaster> forecaster = new ArrayList<>(24);

        for (int a = 0; a < 24; a++) {
            forecaster.add(new WekaForecaster());
        }

        int a = 0;

        for (WekaForecaster fore : forecaster) {

            //Defimimos el atributo que queremos predecir
            fore.setFieldsToForecast("Total");

            //Definimos el mtodo de prediccin a emplear. En este caso, regresin lineal porque 
            //en el artculo es el que mejor ha funcionado
            fore.setBaseForecaster(new LinearRegression());

            //Defimimos el atributo que "marca" el tiempo y su peridiocidad
            fore.getTSLagMaker().setTimeStampField("Intervalo");
            fore.getTSLagMaker().setMinLag(1);
            fore.getTSLagMaker().setMaxLag(1);

            fore.getTSLagMaker().setPeriodicity(TSLagMaker.Periodicity.WEEKLY);

            fore.buildForecaster(pasos.get(a), System.out);

            // System.err.println(pasos.get(a).toString());

            //System.err.printf("Termin");

            fore.primeForecaster(pasos.get(a));

            List<List<NumericPrediction>> forecast = fore.forecast(1, System.out);

            System.err.println("==== " + a + " ====");
            // output the predictions. Outer list is over the steps; inner list is over
            // the targets
            for (int i = 0; i < 1; i++) {
                List<NumericPrediction> predsAtStep = forecast.get(i);
                for (int j = 0; j < 1; j++) {
                    NumericPrediction predForTarget = predsAtStep.get(j);
                    System.err.print("" + predForTarget.predicted() + " ");
                }
                System.err.println();
            }
            a++;
        }
        /*    
                    
           // path to the Australian wine data included with the time series forecasting
           // package
           String pathToWineData = weka.core.WekaPackageManager.PACKAGES_DIR.toString()
             + File.separator + "timeseriesForecasting" + File.separator + "sample-data"
             + File.separator + "wine.arff";
                
           // load the wine data
           Instances wine = new Instances(new BufferedReader(new FileReader(pathToWineData)));      
                   
           // new forecaster
           WekaForecaster forecaster = new WekaForecaster();
                
           // set the targets we want to forecast. This method calls
           // setFieldsToLag() on the lag maker object for us
           forecaster.setFieldsToForecast("Fortified,Dry-white");
                
           // default underlying classifier is SMOreg (SVM) - we'll use
           // gaussian processes for regression instead
           forecaster.setBaseForecaster(new GaussianProcesses());
                
           forecaster.getTSLagMaker().setTimeStampField("Date"); // date time stamp
           forecaster.getTSLagMaker().setMinLag(1);
           forecaster.getTSLagMaker().setMaxLag(12); // monthly data
                
           // add a month of the year indicator field
           forecaster.getTSLagMaker().setAddMonthOfYear(true);
                
           // add a quarter of the year indicator field
           forecaster.getTSLagMaker().setAddQuarterOfYear(true);
                
           // build the model
           forecaster.buildForecaster(wine, System.out);
                
           // prime the forecaster with enough recent historical data
           // to cover up to the maximum lag. In our case, we could just supply
           // the 12 most recent historical instances, as this covers our maximum
           // lag period
           forecaster.primeForecaster(wine);
                
           // forecast for 12 units (months) beyond the end of the
           // training data
           <<List<List<NumericPrediction>> forecast = forecaster.forecast(12, System.out);
                
                   
                   
           // output the predictions. Outer list is over the steps; inner list is over
           // the targets
           for (int i = 0; i < 12; i++) {
             List<NumericPrediction> predsAtStep = forecast.get(i);
             for (int j = 0; j < 2; j++) {
               NumericPrediction predForTarget = predsAtStep.get(j);
               System.out.print("" + predForTarget.predicted() + " ");
             }
             System.out.println();
           }
                
           // we can continue to use the trained forecaster for further forecasting
           // by priming with the most recent historical data (as it becomes available).
           // At some stage it becomes prudent to re-build the model using current
           // historical data.
        */
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}