TBATS for Time Series Forecasting
tbats is a Python library implementing BATS and TBATS models for time series forecasting, known for handling complex seasonality and Box-Cox transformations. The current version is 1.1.3, and it receives updates primarily for bug fixes, dependency upgrades, and occasional feature enhancements, with an irregular release cadence.
Warnings
- gotcha Prior to version 1.1.3, numeric precision issues could cause Box-Cox transformations to fail or produce incorrect results in certain scenarios.
- breaking In version 1.1.0, the default method for spawning new processes for parallel execution (`n_jobs > 1`) was changed from the system default to 'spawn'. This may alter behavior, particularly on Windows or macOS where the default 'fork' method has different implications.
- gotcha Versions prior to 1.0.6 (and specifically 1.0.5 had fixes) suffered from resource leaks where multiprocessing pools were not reliably closed, potentially leading to 'too many open files' errors or system instability.
- gotcha When `n_jobs=1` was specified in versions prior to 1.0.9, subprocesses might still have been triggered, leading to unnecessary overhead or potential issues with environments not configured for multiprocessing.
Install
-
pip install tbats
Imports
- TBATS
from tbats import TBATS
Quickstart
import numpy as np
from tbats import TBATS
# Generate some example time series data with seasonality
np.random.seed(42)
n_points = 100
seasonal_period = 24 # Daily seasonality
t = np.arange(n_points)
y = 50 + 2 * t + 10 * np.sin(2 * np.pi * t / seasonal_period) + np.random.normal(0, 5, n_points)
# Create and fit the TBATS model
estimator = TBATS(seasonal_periods=[seasonal_period],
use_box_cox=True,
use_trend=True,
use_damped_trend=False,
use_arma_errors=True,
n_jobs=1)
model = estimator.fit(y)
# Make a forecast
forecast = model.forecast(steps=10)
print("Original series (last 5 points):", y[-5:])
print("Forecasted values (next 10 steps):", forecast)