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
    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.

For example:

  • 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.



This is a comment but due to lack of reputation posted as answer.

Have you tried comparing forecast result with croston libraries in R?


  • $\begingroup$ yes, I tried and it gives different results unfortunately, and if you give without zero array( such as x=[2,4,12,18,24,8]) it produces same exact predictions as demand. It is too good to be true:) $\endgroup$ – Tyr Sep 1 '20 at 8:27
  • $\begingroup$ you can find the comparision on github.com/HamidM6/croston/issues/2 $\endgroup$ – Tyr Sep 1 '20 at 8:41

I am struggling with this problem as well, but I think I see what is going wrong in your case.

In your code you are concattenating the croston_fittedvalues and the croston_forecast. However, you are adding two different things. You expect the fitted values to also be a forecast, but this is exactly what it is: the model fit. The model only provides one forecast (your last value).

However, I am no this library. I still struggle to get realistic results (all my predictions seem to be close to 1).



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.