Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Croston Method #97

Closed
antoinecarme opened this issue Jul 27, 2018 · 6 comments
Closed

Add Croston Method #97

antoinecarme opened this issue Jul 27, 2018 · 6 comments

Comments

@antoinecarme
Copy link
Owner

This is a quite known method for forecasting intermittent demand (time series with a small number of non-zero observations).

R implementation :

https://www.rdocumentation.org/packages/forecast/versions/8.4/topics/croston

See if Croston method can be implemented efficiently as the last component of a PyAF signal decompostion (any other option ?).

@antoinecarme
Copy link
Owner Author

antoinecarme commented Jul 27, 2018

some references :

  1. The FPP2 book by Rob J Hyndman and George Athanasopoulos :
    https://otexts.org/fpp2/counts.html
    With a very nice description of the time series of counts models and an example time series dataset
    image

  2. More sophisticated/specialized tsintermittent package for R by Nikolaos Kourentzes .
    https://cran.r-project.org/package=tsintermittent
    http://kourentzes.com/forecasting/2014/06/23/intermittent-demand-forecasting-package-for-r/
    https://github.com/trnnick/tsintermittent

    => Two datasets

  3. Good presentation :
    https://www.lancaster.ac.uk/media/lancaster-university/content-assets/documents/lums/forecasting/presentations/Petropoulosetal.-ISIR2014-Anotherlookatestimatorsforintermittentdemand.pdf
    image

         = > RAF dataset + Automotive dataset
    

antoinecarme added a commit that referenced this issue Oct 24, 2018
Added a prototyping notebook
antoinecarme added a commit that referenced this issue Oct 25, 2018
Added a notebook
antoinecarme added a commit that referenced this issue Oct 25, 2018
Updated this notebook
antoinecarme added a commit that referenced this issue Oct 29, 2018
Added some tests
antoinecarme added a commit that referenced this issue Oct 29, 2018
Added some options to control croston model.
antoinecarme added a commit that referenced this issue Oct 29, 2018
Allow building croston models (disabled by default)
antoinecarme added a commit that referenced this issue Oct 29, 2018
Real croston implementation (WIP)
@antoinecarme
Copy link
Owner Author

Croston options (with default values) :

class cCrostonOptions:
    def __init__(self):
        # can be : "CROSTON" , "SBJ" , "SBA", everything else is equivalent to "CROSTON"
        self.mMethod = None;
        self.mAlpha = 0.1
        # minimum amount of zeros for a series to be intermittent
        self.mZeroRate = 0.1

@antoinecarme
Copy link
Owner Author

antoinecarme commented Oct 29, 2018

Sample script with croston model :

https://github.com/antoinecarme/pyaf/blob/croston/tests/croston/croston_test_1_SBJ.py

and log :

INFO:pyaf.std:START_TRAINING 'Signal'
INFO:pyaf.std:END_TRAINING_TIME_IN_SECONDS 'Signal' 5.448007345199585
INFO:pyaf.std:TIME_DETAIL TimeVariable='Date' TimeMin=2016-01-25T00:00:00.000000 TimeMax=2016-11-05T00:00:00.000000 TimeDelta=<DateOffset: days=1> Horizon=7
INFO:pyaf.std:SIGNAL_DETAIL_ORIG SignalVariable='Signal' Min=0.0 Max=97.0  Mean=1.0520547945205478 StdDev=8.398631812727873
INFO:pyaf.std:SIGNAL_DETAIL_TRANSFORMED TransformedSignalVariable='_Signal' Min=0.0 Max=97.0  Mean=1.0520547945205478 StdDev=8.398631812727873
INFO:pyaf.std:BEST_TRANSOFORMATION_TYPE '_'
INFO:pyaf.std:BEST_DECOMPOSITION  '_Signal_ConstantTrend_residue_zeroCycle_residue_CROSTON(0.1)' [ConstantTrend + NoCycle + CROSTON]
INFO:pyaf.std:TREND_DETAIL '_Signal_ConstantTrend' [ConstantTrend]
INFO:pyaf.std:CYCLE_DETAIL '_Signal_ConstantTrend_residue_zeroCycle' [NoCycle]
INFO:pyaf.std:AUTOREG_DETAIL '_Signal_ConstantTrend_residue_zeroCycle_residue_CROSTON(0.1)' [CROSTON]
INFO:pyaf.std:MODEL_MAPE MAPE_Fit=166570291253.2988 MAPE_Forecast=23597014621.9707 MAPE_Test=20278312516.2075
INFO:pyaf.std:MODEL_SMAPE SMAPE_Fit=1.9795 SMAPE_Forecast=1.9986 SMAPE_Test=2.0
INFO:pyaf.std:MODEL_MASE MASE_Fit=8.7383 MASE_Forecast=1.5821 MASE_Test=20278312516.2075
INFO:pyaf.std:MODEL_L1 L1_Fit=17.292699561061582 L1_Forecast=3.3870926948121 L1_Test=2.0278312516207504
INFO:pyaf.std:MODEL_L2 L2_Fit=24.449633384717657 L2_Forecast=9.04022326571336 L2_Test=2.0278312516207504
INFO:pyaf.std:MODEL_COMPLEXITY 2
INFO:pyaf.std:AR_MODEL_DETAIL_START
INFO:pyaf.std:AR_MODEL_DETAIL_END

@antoinecarme
Copy link
Owner Author

antoinecarme commented Oct 29, 2018

image

antoinecarme added a commit that referenced this issue Oct 29, 2018
Added a demo notebook
antoinecarme added a commit that referenced this issue Oct 30, 2018
Updated this test
antoinecarme added a commit that referenced this issue Oct 30, 2018
Correcetd croston forecast (constant)
antoinecarme added a commit that referenced this issue Oct 30, 2018
Correcetd croston output
antoinecarme added a commit that referenced this issue Oct 30, 2018
fpp2 counts example
@antoinecarme
Copy link
Owner Author

antoinecarme commented Oct 30, 2018

antoinecarme added a commit that referenced this issue Oct 30, 2018
fill first empty fit data with zero counts (when signal starts with zeros)
antoinecarme added a commit that referenced this issue Oct 31, 2018
Added two more tests
antoinecarme added a commit that referenced this issue Oct 31, 2018
Allow optimizing alpha when not set (cCrostonOptions.mAlpha = None)
antoinecarme added a commit that referenced this issue Oct 31, 2018
Allow optimizing alpha when not set (cCrostonOptions.mAlpha = None)
antoinecarme added a commit that referenced this issue Oct 31, 2018
Updated Makefile. Added croston tests
antoinecarme added a commit that referenced this issue Nov 1, 2018
Added some test reference logs
antoinecarme added a commit that referenced this issue Nov 1, 2018
Updated this notebook
antoinecarme added a commit that referenced this issue Nov 1, 2018
@antoinecarme
Copy link
Owner Author

antoinecarme commented Nov 1, 2018

Fixed.

Croston method is now supported but not used by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant