Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
edited tags
Source Link
kjetil b halvorsen
  • 82.8k
  • 32
  • 201
  • 663

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  
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    
yhat_croston =pd.DataFrame(np.concatenate([fit_pred_croston['croston_fittedvalues'][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

result_table

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

Thanks,

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

result_table

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

Thanks,

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

result_table

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

edited tags
Link
kjetil b halvorsen
  • 82.8k
  • 32
  • 201
  • 663
Bumped by Community user
Bumped by Community user
Source Link
Tyr
  • 111
  • 1
  • 3

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

result_table

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

Thanks,