π
Scalecast: Dynamic Forecasting at Scale
About
This package uses a scaleable forecasting approach in Python with common scikit-learn and statsmodels, as well as Facebook Prophet, Microsoft LightGBM and LinkedIn Silverkite models, to forecast time series. Use your own regressors or load the object with its own seasonal, auto-regressive, and other regressors, or combine all of the above. All forecasting is dynamic by default so that auto-regressive terms can be used without leaking data into the test set, setting it apart from other time-series libraries. Dynamic model testing can be disabled to improve model evaluation speed. Differencing to achieve stationarity is built into the library and metrics can be compared across the time series' original level or first or second difference. This library was written to easily apply and compare many forecasts fairly across the same series.
import pandas as pd
import pandas_datareader as pdr
from scalecast import GridGenerator
from scalecast.Forecaster import Forecaster
models = ('mlr','knn','svr','xgboost','elasticnet','mlp','prophet')
df = pdr.get_data_fred('HOUSTNSA',start='2009-01-01',end='2021-06-01')
GridGenerator.get_example_grids()
f = Forecaster(y=df.HOUSTNSA,current_dates=df.index) # to initialize, specify y and current_dates (must be arrays of the same length)
f.set_test_length(12) # specify a test length for your models - do this before eda
f.generate_future_dates(24) # this will create future dates that are on the same interval as the current dates and it will also set the forecast length
f.add_ar_terms(4) # add AR terms before differencing
f.add_AR_terms((2,12)) # seasonal AR terms
f.integrate() # automatically decides if the y term and all ar terms should be differenced to make the series stationary
f.add_seasonal_regressors('month',raw=False,sincos=True) # uses pandas attributes: raw=True creates integers (default), sincos=True creates wave functions
f.add_seasonal_regressors('year')
f.add_covid19_regressor() # dates are flexible, default is from when disney world closed to when US CDC lifted mask recommendations
f.add_time_trend()
f.set_validation_length(6) # length, different than test_length, to tune the hyperparameters
f.tune_test_forecast(models)
f.plot(order_by='LevelTestSetMAPE',level=True) # plots the forecast
Why switch to Scalecast?
- Much simpler to set up than a tensorflow neural network
- Extends scikit-learn regression modeling concepts to be useful for time-series forecasting
- propogates lagged y terms dynamically
- differences and undifferences series with ease to model stationary series only
- Allows comparison of many different modeling concepts, including ARIMA, MLR, MLP, and Prophet so you never have to be in doubt about which model is right for your series
- Your results and accuracy metrics can always be level, even if you need to difference the series to model it effectively
Installation
pip install scalecast
- installs the base package and most dependencies
pip install fbprophet
- only necessary if you plan to forecast with Facebook prophet models
- to resolve a common installation issue, see this Stack Overflow post
pip install greykite
- only necessary if you plan to forecast with LinkedIn Silverkite
- If using notebook functions:
pip install tqdm
pip install ipython
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
- if using Jupyter Lab:
jupyter labextension install @jupyter-widgets/jupyterlab-manager
Documentation
Documentation | |
---|---|
|
Get straight to the process |
|
Read the 3-part series |
|
Play with an example in your browser |
|
See what's changed |
|
Review all high-level concepts in the library |
Contribute
The following contributions are needed (contact [email protected])
- Documentation moved to a proper website with better organization
- Confidence intervals for all models (need to be consistently derived and able to toggle on/off or at different levels: 95%, 80%, etc.)
- Error/issue reporting