I tried to use croston method for intermittent forecasting via croston package which is available in below link:
below code creates a sample ts and creates forecast via croston method.
import pandas as pd import numpy as np from croston import croston x=np.array([0,0,0,10,0,4,0,0,5,0,0,0,2,10,0,20,2,18,0,0,14,4,12,0,0,0 ,3,1,0,16,4]) fit_pred_croston = croston.fit_croston(x,1,'original') yhat_croston =pd.DataFrame(np.concatenate([fit_pred_croston['croston_fittedvalues' ], fit_pred_croston['croston_forecast']])) x = pd.DataFrame(np.hstack((x,np.array(['forecast'])))) result_sample = pd.merge(x, yhat_croston, left_index=True, right_index=True) result_sample.columns = ['Demand','Forecast']
In this method forecast is created in the same period of time that demand occurs. Below table represents 'result_sample' that calculated in code.
- when time = 0, demand = 0 and forecast = 0 which is expected
- when time = 3, demand = 10 and forecast = 5
which is odd because there is not any demand before that period. In my opinion calculation is correct but need to be shifted by 1.
- when time = 3, demand = 10, forecast should be 0
- when time = 4, demand = 0, forecast should be 5
I contacted with author of method(I thought it is something like bug) but we couldn't agree on this. I'm quite curious what do you think or what do you suggest. Any comment might help the solve the issue.
In below link you can find our discussion as well.