# Croston method with python, demand doesn't effect forecast properly?

I tried to use croston method for intermittent forecasting via croston package which is available in below link:

https://pypi.org/project/croston/

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.

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.

https://github.com/HamidM6/croston/issues/1

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

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

tsintermittent

• 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:) – Tyr Sep 1 '20 at 8:27
• you can find the comparision on github.com/HamidM6/croston/issues/2 – 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).

Daan