Skip to main content

The practitioner's time series forecasting library

Project description

Scalecast

Scalecast Logo

About

Scalecast helps you forecast time series. What sets it apart from other libraries is its pipelining functionality. The unique approach not only allows a series to be transformed to account for stationarity and other concerns, but also fully reverted when results are ready to be reported. Point forecasts, test-set metrics, and conformal confidence intervals are easily obtained at the original series level through this process. Uniform ML modeling (with models from a diverse set of libraries, including scikit-learn, statsmodels, and tensorflow), reporting, and data visualizations are offered through the Forecaster and MVForecaster interfaces. Data storage and processing then becomes easy as all applicable data, predictions, and many derived metrics are contained in a few objects with much customization available through different modules. Feature requests and issue reporting are welcome!

Documentation

Example Starter Code

from scalecast.Forecaster import Forecaster
from scalecast.Pipeline import Pipeline, Transformer, Reverter
from scalecast.auxmodels import mlp_stack
from scalecast import GridGenerator
import matplotlib.pyplot as plt
import pandas_datareader as pdr

# add more/fewer models to the below tuple
models = (
  'mlr',
  'elasticnet',
  'lightgbm',
  'knn',
) # https://scalecast.readthedocs.io/en/latest/Forecaster/_forecast.html
# grids for tuning models: https://github.com/mikekeith52/scalecast/tree/main/src/scalecast/grids
# extract data (this is an example dataset)
df = pdr.get_data_fred(
    'HOUSTNSA',
    start='1959-01-01',
    end='2022-08-01'
)
# build the forecaster object
f = Forecaster(
    y=df['HOUSTNSA'],
    current_dates=df.index,
    future_dates=24,
    test_length=48, # not required to set a test length but testing models is necessary for generating confidence intervals
    cis = True, # all models called will have confidence intervals if this is True (default is False)
)
# this function will be placed in a pipeline
def forecaster(f,models):
    f.add_covid19_regressor()
    f.auto_Xvar_select() # https://scalecast-examples.readthedocs.io/en/latest/misc/auto_Xvar/auto_Xvar.html
    f.tune_test_forecast(
        models,
        dynamic_testing=24, # test-set metrics will be an average of rolling 24-step forecasts
        cross_validate=True, # models tuned with cross-validation, excludes test set
        k = 3, # 3-fold (time series) cross validation
        rolling = False, # rolling cross validation available
    )
    mlp_stack(f,models) # a stacking model offered by scalecast
# transform data to make it stationary/easier to predict        
transformer = Transformer(
    transformers = [
        ('DiffTransform',1),
        ('DiffTransform',12),
    ],
)
reverter = Reverter(
    # list reverters in reverse order
    reverters = [
        ('DiffRevert',12),
        ('DiffRevert',1),
    ],
    base_transformer = transformer,
)
pipeline = Pipeline(
    steps = [
        ('Transform',transformer),
        ('Forecast',forecaster),
        ('Revert',reverter),
    ],
)
f = pipeline.fit_predict(f,models=models)
backtest_results = pipeline.backtest(f,models=models)
f.plot(
    ci=True, # setting this to True will not throw an error if there are no confidence intervals
    order_by='TestSetMAPE',
)
plt.legend(loc = 'upper left')
plt.show()
# export results
results = f.export(
    [
      'model_summaries', # info about hyperparams, xvars, scaling, error metrics, etc.
      'all_fcsts', # point forecasts
    ],
    cis = True, # confidence intervals placed on point forecasts
)

Readme Example Vis

Installation

  • Only the base package is needed to get started:
    • pip install --upgrade scalecast
  • Optional add-ons:
    • pip install tensorflow (for RNN/LSTM on Windows) or pip install tensorflow-macos (for MAC/M1)
    • pip install darts
    • pip install prophet
    • pip install greykite (for the silverkite model)
    • pip install shap (SHAP feature importance)
    • pip install kats (changepoint detection)
    • pip install pmdarima (auto arima)
    • pip install tqdm (progress bar for notebook)
    • pip install ipython (widgets for notebook)
    • pip install ipywidgets (widgets for notebook)
    • jupyter nbextension enable --py widgetsnbextension (widgets for notebook)
    • jupyter labextension install @jupyter-widgets/jupyterlab-manager (widgets for Lab)

Features and Articles

Forecasting with Different Model Types

Transforming and Reverting

Confidence Intervals

Dynamic Validation

Model Input Selection

Scaled Forecasting on Many Series

Anomaly Detection

Contributing

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SCALECAST-0.17.9.tar.gz (738.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page