signaflo / java-timeseries

Time series analysis in Java
MIT License
195 stars 49 forks source link

Something is wrong #35

Open y913403515 opened 5 years ago

y913403515 commented 5 years ago

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!

MuhYusuf93 commented 5 years ago

@y913403515 yeah me too :(

signaflo commented 4 years ago

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.