Skip to main content

BATS and TBATS for time series forecasting

Project description

BATS and TBATS time series forecasting

Package provides BATS and TBATS time series forecasting methods described in:

De Livera, A.M., Hyndman, R.J., & Snyder, R. D. (2011), Forecasting time series with complex seasonal patterns using exponential smoothing, Journal of the American Statistical Association, 106(496), 1513-1527.


From pypi:

pip install tbats

Import via:

from tbats import BATS, TBATS

Minimal working example:

from tbats import TBATS
import numpy as np

# required on windows for multi-processing,
# see
if __name__ == '__main__':
    t = np.array(range(0, 160))
    y = 5 * np.sin(t * 2 * np.pi / 7) + 2 * np.cos(t * 2 * np.pi / 30.5) + \
        ((t / 20) ** 1.5 + np.random.normal(size=160) * t / 50) + 10
    # Create estimator
    estimator = TBATS(seasonal_periods=[14, 30.5])
    # Fit model
    fitted_model =
    # Forecast 14 steps ahead
    y_forecasted = fitted_model.forecast(steps=14)
    # Summarize fitted model

Reading model details

# Time series analysis
print(fitted_model.y_hat) # in sample prediction
print(fitted_model.resid) # in sample residuals

# Reading model parameters

See examples directory for more details.


BATS and TBATS tries multitude of models under the hood and may appear slow when fitting to long time series. In order to speed it up you can start with constrained model search space. It is recommended to run it without Box-Cox transformation and ARMA errors modelling that are the slowest model elements:

# Create estimator
estimator = TBATS(
    seasonal_periods=[14, 30.5],
    use_arma_errors=False,  # shall try only models without ARMA
    use_box_cox=False  # will not use Box-Cox
fitted_model =

In some environment configurations parallel computation of models freezes. Reason for this is unclear yet. If the process appears to be stuck you can try running it on a single core:

estimator = TBATS(
    seasonal_periods=[14, 30.5],
fitted_model =

For Contributors

Building package:

pip install -e .[dev]

Unit and integration tests:

pytest test/

R forecast package comparison tests. Those DO NOT RUN with default test command, you need R and forecast package installed:

pytest test_R/

Comparison to R implementation

Python implementation is meant to be as much as possible equivalent to R implementation in forecast package.

Project details

Download files

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

Source Distribution

tbats-1.1.1.tar.gz (32.4 kB view hashes)

Uploaded Source

Built Distribution

tbats-1.1.1-py3-none-any.whl (43.8 kB view hashes)

Uploaded Python 3

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