Я новичок в Weka. У меня есть еженедельный набор данных температур за последние 10 лет. Используя этот набор данных, я собираюсь прогнозировать недельную температуру в следующем году. Ниже я прикрепил код.
import java.io.*;
import java.util.List;
import weka.core.Instances;
import weka.filters.supervised.attribute.TSLagMaker;
import weka.classifiers.functions.GaussianProcesses;
import weka.classifiers.evaluation.NumericPrediction;
import weka.classifiers.timeseries.WekaForecaster;
import org.joda.time.*;
public class TimeSeriesExample {
public static void main(String[] args) {
try {
// path to data set
Instances temp = new Instances(new BufferedReader(new FileReader("sample-data/weeklyMaxTemp.arff")));
// new forecaster
WekaForecaster forecaster = new WekaForecaster();
// set the targets to forecast
forecaster.setFieldsToForecast("BMxT");
forecaster.setBaseForecaster(new GaussianProcesses());
forecaster.getTSLagMaker().setTimeStampField("Date");
// if there are not enough values in the recent history, return a
// negative value indicating the steps to wait
if (forecaster.getTSLagMaker().getMaxLag() > temp.size()) {
System.out.println("Not enough recent values to make predictions.");
}
// add a week 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(temp, System.out);
forecaster.primeForecaster(temp);
// forecast for 52 units (weeks) beyond the end of the training data
List<List<NumericPrediction>> forecast = forecaster.forecast(52, System.out);
DateTime currentDt = getCurrentDateTime(forecaster.getTSLagMaker());
// output the predictions
for (int i = 0; i < 52; ++i) {
List<NumericPrediction> predsAtStep = forecast.get(i);
for (int j = 0; j < 1; ++j) {
NumericPrediction predForTarget = predsAtStep.get(j);
System.out.print(currentDt + " ->> " + predForTarget.predicted() + " ");
}
System.out.println();
currentDt = advanceTime(forecaster.getTSLagMaker(), currentDt);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static DateTime getCurrentDateTime(TSLagMaker lm) throws Exception {
return new DateTime((long) lm.getCurrentTimeStampValue());
}
private static DateTime advanceTime(TSLagMaker lm, DateTime dt) {
return new DateTime((long) lm.advanceSuppliedTimeValue(dt.getMillis()));
}
}
52 означает количество недель в году.
// forecast for 24 units (weeks) beyond the end of the training data
List<List<NumericPrediction>> forecast = forecaster.forecast(52, System.out);
Когда я запускаю код, он выдает 52 недельных значения. Но результат начинается с 52-й недели с последних данных набора тренировочных данных.
Это означает, что последний день моего набора тренировочных данных - 2015.12.30. Следующее прогнозируемое значение должно быть на 2016.01.06. Но приведенный набор данных начинается через 52 недели.
Как я могу решить проблему.