java-timeseries icon indicating copy to clipboard operation
java-timeseries copied to clipboard

Something is wrong

Open y913403515 opened this issue 6 years ago • 2 comments

When I run java-timeseries with the following data, something is wrong.

double[] sales = new double[] {3.0, 3.0, 7.0, 2.0, 2.0, 1.0, 0.0, 3.0, 4.0, 3.0, 2.0, 3.0, 6.0, 1.0, 
                                                0.0, 3.0, 4.0, 2.0, 2.0, 0.0, 1.0};
long season = 8l;

TimePeriod   day = TimePeriod.oneDay();
TimeSeries   series = TimeSeries.from(day, sales);
TimePeriod   timePeriod = new TimePeriod(TimeUnit.DAY, season);
ArimaOrder   order = ArimaOrder.order(3, 1, 2, 1, 1, 2);
Arima             model = Arima.model(series, order, timePeriod);

Forecast forecast = model.forecast(7);
TimeSeries forecastValue = forecast.pointEstimates();
double[] forecastValuesArray = forecastValue.asArray();

 for ( double  forecastValue : forecastValuesArray) {
                System.out.println(forecastValue);
            }

Then the printed results are all NaN.

Thanks!

y913403515 avatar May 28 '19 08:05 y913403515

@y913403515 yeah me too :(

MuhYusuf93 avatar May 30 '19 13:05 MuhYusuf93

Sorry for the late response @y913403515. I'm just getting back to this project after a long time away.

You need to have more observations than the length of your seasonal cycle. For example, it wouldn't make sense to fit a monthly seasonal model with only 4 observations, which is roughly equivalent to what you're trying to do here.

Ideally, the number of observations you have should be at least twice the length of your seasonal cycle. So, in case your cycle is 81 days long, you should have 162 observations, but even then your forecast is going to be very unreliable. Think of fitting a seasonal model with only two years worth of monthly data. It's not enough data to learn from.

I'm not going to close this issue because one, I would like to see if I can give a better explanation of why this doesn't work, and two, there needs to be an error message in this circumstance instead of pumping out NaN values.

signaflo avatar Oct 29 '19 09:10 signaflo