antoinecarme / pyaf

PyAF is an Open Source Python library for Automatic Time Series Forecasting built on top of popular pydata modules.
BSD 3-Clause "New" or "Revised" License
457 stars 73 forks source link

Add Multiplicative Models/Seasonals #178

Closed antoinecarme closed 2 years ago

antoinecarme commented 2 years ago

PyAF uses an additive signal decomposition of the type \Phi( Trend + Seasonal + AR), where \Phi is a signal transformation.

It is interesting to add multiplicative decompositions to allow more diverse models. A decomposition can be of the form \Phi( Trend Seasonal + AR) or \Phi( Trend Seasonal * AR). More general models can be generated this way and allow exploring more forecast types/spaces.

  1. Add Options.mDecompositionTypes = ['T+S+R' , 'TS+R' , 'TSR']. Give control to the user/model. PyAF does not try to detect if the seasonality is additive or multiplicative. It tries all possible models , including both seasonality types and keeps the best model (best MAPE). CPU time is cheap.
  2. Compute incremental remainders/residues based on the decomposition type (trend residues, seasonal residues, etc).
  3. Only 'T+S+R' is enabled by default (fast mode). Slow mode activates all decomposition types. User customizable.
  4. Each decomposition type goes on a specific CPU.
  5. In some cases, multiplicative models are not applicable (negative or zero values in the signal or its residues)

References :

  1. Forecasting: Principles and Practice (3rd ed) By Rob J Hyndman and George Athanasopoulos. https://otexts.com/fpp3/decomposition.html
  2. https://otexts.com/fpp3/classical-decomposition.html

Target Release : 2022-07-14

antoinecarme commented 2 years ago

Impact on plots ?

antoinecarme commented 2 years ago

Demo notebook.

antoinecarme commented 2 years ago

First demo dataset : wineind: Australian total wine sales

https://www.rdocumentation.org/packages/forecast/versions/8.1/topics/wineind

antoinecarme commented 2 years ago

Summary of implementation details :

Updated Options. Only additive models are activated by default Generate all models with all possible decomposition types. Handle slow mode. XGBoost and LightGBM models are optional. Compute trend residues Compute cycle residues Compute AR residues Compute AR/Keras/Intermittent/Scikit models residues Added some functional tests Added sample jupyter notebooks with the same dataset and different model settings (T+S+R, TS+R, TSR, slow) ZeroAR constant value is 1.0 sometimes. ZeroCycle constant value is 1.0 in multiplicative models Updated model formula (informative) Use series.dtype instead of np.dtype(series). CicleCI effects Corrected typing of intermediate columns. Avoid unnecessary SettingWithCopyWarning Handle division by zeros in multiplicative models residues. Compute residues is not that easy!!! Avoid dataframe fragmentation warnings. Added some tests (slooooooow, for debugging purposes) Disable cross-validation by default in slow mode. Can be reenabled manually. Update model complexity. Additive models are simpler than multiplicative ones. Refactored model selection. Probably some issues corrected with very large models.

antoinecarme commented 2 years ago

Added a report on the model selection as a dataframe with the best MAPE models , sorted by complexity.

lEngine.mSignalDecomposition.mModelShortList

image

antoinecarme commented 2 years ago

Fixed.