# 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.
## Installation
From pypi:
```bash
pip install tbats
```
Import via:
```python
from tbats import BATS, TBATS
```
## Minimal working example:
```python
from tbats import TBATS
import numpy as np
# required on windows for multi-processing,
# see https://docs.python.org/2/library/multiprocessing.html#windows
if __name__ == '__main__':
np.random.seed(2342)
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 = estimator.fit(y)
# Forecast 14 steps ahead
y_forecasted = fitted_model.forecast(steps=14)
# Summarize fitted model
print(fitted_model.summary())
```
Reading model details
```python
# Time series analysis
print(fitted_model.y_hat) # in sample prediction
print(fitted_model.resid) # in sample residuals
print(fitted_model.aic)
# Reading model parameters
print(fitted_model.params.alpha)
print(fitted_model.params.beta)
print(fitted_model.params.x0)
print(fitted_model.params.components.use_box_cox)
print(fitted_model.params.components.seasonal_harmonics)
```
See **examples** directory for more details
## For Contributors
Building package:
```bash
pip install -e .[dev]
```
Unit and integration tests:
```bash
python setup.py test
```
R forecast package comparison tests. Those DO NOT RUN with default test command, you need R forecast package installed:
```bash
python setup.py test_r
```
## Comparison to R implementation
Python implementation is meant to be as much as possible equivalent to R implementation in forecast package.
- BATS in R https://www.rdocumentation.org/packages/forecast/versions/8.4/topics/bats
- TBATS in R: https://www.rdocumentation.org/packages/forecast/versions/8.4/topics/tbats
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.
## Installation
From pypi:
```bash
pip install tbats
```
Import via:
```python
from tbats import BATS, TBATS
```
## Minimal working example:
```python
from tbats import TBATS
import numpy as np
# required on windows for multi-processing,
# see https://docs.python.org/2/library/multiprocessing.html#windows
if __name__ == '__main__':
np.random.seed(2342)
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 = estimator.fit(y)
# Forecast 14 steps ahead
y_forecasted = fitted_model.forecast(steps=14)
# Summarize fitted model
print(fitted_model.summary())
```
Reading model details
```python
# Time series analysis
print(fitted_model.y_hat) # in sample prediction
print(fitted_model.resid) # in sample residuals
print(fitted_model.aic)
# Reading model parameters
print(fitted_model.params.alpha)
print(fitted_model.params.beta)
print(fitted_model.params.x0)
print(fitted_model.params.components.use_box_cox)
print(fitted_model.params.components.seasonal_harmonics)
```
See **examples** directory for more details
## For Contributors
Building package:
```bash
pip install -e .[dev]
```
Unit and integration tests:
```bash
python setup.py test
```
R forecast package comparison tests. Those DO NOT RUN with default test command, you need R forecast package installed:
```bash
python setup.py test_r
```
## Comparison to R implementation
Python implementation is meant to be as much as possible equivalent to R implementation in forecast package.
- BATS in R https://www.rdocumentation.org/packages/forecast/versions/8.4/topics/bats
- TBATS in R: https://www.rdocumentation.org/packages/forecast/versions/8.4/topics/tbats
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.0.7.tar.gz
(30.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
tbats-1.0.7-py3-none-any.whl
(42.9 kB
view details)
File details
Details for the file tbats-1.0.7.tar.gz.
File metadata
- Download URL: tbats-1.0.7.tar.gz
- Upload date:
- Size: 30.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27fd55088e432c8e66e42ad13ee73d0d509836db95c094046bd65387ca8b2797
|
|
| MD5 |
bd1ddd04bf6ba704fcea2ebd82598244
|
|
| BLAKE2b-256 |
0ddd442c0dd7b52200be910afaa7ee81704a427da1f18a857b3ec7398a0be35d
|
File details
Details for the file tbats-1.0.7-py3-none-any.whl.
File metadata
- Download URL: tbats-1.0.7-py3-none-any.whl
- Upload date:
- Size: 42.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c6a109016d2fb9688f5708184d9dda332e906cca35dc31415779995f264d273
|
|
| MD5 |
5c018d6e372e66d6b7bf7a6161ce86d3
|
|
| BLAKE2b-256 |
e222c8e024d013e75dc23ded89c5d6f3364211f54cd13701d987ace6ce1133a5
|