A python package for time series forecasting with scikit-learn estimators.
Project description
tspiral
A python package for time series forecasting with scikit-learn estimators.
tspiral is not a library that works as a wrapper for other tools and methods for time series forecasting. tspiral directly provides scikit-learn estimators for time series forecasting. It leverages the benefit of using scikit-learn syntax and components to easily access the open source ecosystem built on top of the scikit-learn community. It easily maps a complex time series forecasting problems into a tabular supervised regression task, solving it with a standard approach.
Overview
tspiral provides 4 optimized forecasting techniques:
- Recursive Forecasting
Lagged target features are combined with exogenous regressors (if provided) and lagged exogenous features (if specified). A scikit-learn compatible regressor is fitted on the whole merged data. The fitted estimator is called iteratively to predict multiple steps ahead.
Which in a compact way we can summarize in:
- Direct Forecasting
A scikit-learn compatible regressor is fitted on the lagged data for each time step to forecast.
Which in a compact way we can summarize in:
It's also possible to mix recursive and direct forecasting by predicting directly some future horizons while using recursive on the remaining.
- Stacking Forecasting
Multiple recursive time series forecasters are fitted and combined on the final portion of the training data with a meta-learner.
- Rectified Forecasting
Multiple direct time series forecasters are fitted and combined on the final portion of the training data with a meta-learner.
Multivariate time series forecasting is natively supported for all the forecasting methods available.
Installation
pip install --upgrade tspiral
The module depends only on NumPy and Scikit-Learn (>=0.24.2). Python 3.6 or above is supported.
Media
- How to Improve Recursive Time Series Forecasting
- Time Series Forecasting with Feature Selection: Why you may need it
- Forecast Time Series with Missing Values: Beyond Linear Interpolation
- Time Series Forecasting with Conformal Prediction Intervals: Scikit-Learn is All you Need
- Hitting Time Forecasting: The Other Way for Time Series Probabilistic Forecasting
Usage
- Recursive Forecasting
import numpy as np
from sklearn.linear_model import Ridge
from tspiral.forecasting import ForecastingCascade
timesteps = 400
e = np.random.normal(0,1, (timesteps,))
y = 2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e
model = ForecastingCascade(
Ridge(),
lags=range(1,24+1),
use_exog=False,
accept_nan=False
)
model.fit(None, y)
forecasts = model.predict(np.arange(24*3))
- Direct Forecasting
import numpy as np
from sklearn.linear_model import Ridge
from tspiral.forecasting import ForecastingChain
timesteps = 400
e = np.random.normal(0,1, (timesteps,))
y = 2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e
model = ForecastingChain(
Ridge(),
n_estimators=24,
lags=range(1,24+1),
use_exog=False,
accept_nan=False
)
model.fit(None, y)
forecasts = model.predict(np.arange(24*3))
- Stacking Forecasting
import numpy as np
from sklearn.linear_model import Ridge
from sklearn.tree import DecisionTreeRegressor
from tspiral.forecasting import ForecastingStacked
timesteps = 400
e = np.random.normal(0,1, (timesteps,))
y = 2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e
model = ForecastingStacked(
[Ridge(), DecisionTreeRegressor()],
test_size=24*3,
lags=range(1,24+1),
use_exog=False
)
model.fit(None, y)
forecasts = model.predict(np.arange(24*3))
- Rectified Forecasting
import numpy as np
from sklearn.linear_model import Ridge
from sklearn.tree import DecisionTreeRegressor
from tspiral.forecasting import ForecastingRectified
timesteps = 400
e = np.random.normal(0,1, (timesteps,))
y = 2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e
model = ForecastingRectified(
[Ridge(), DecisionTreeRegressor()],
n_estimators=200,
test_size=24*3,
lags=range(1,24+1),
use_exog=False
)
model.fit(None, y)
forecasts = model.predict(np.arange(24*3))
More examples in the notebooks folder.
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
Built Distribution
File details
Details for the file tspiral-0.2.0.tar.gz
.
File metadata
- Download URL: tspiral-0.2.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e7e8bd1e427890c4a7e7c4adafd5ac6ec925a61cac3aee31b1ea06566aac2ae |
|
MD5 | 092595ff75f6da508a4397adee4a9e82 |
|
BLAKE2b-256 | 56c9e4b2916d128d11b79ad8baa6718c371fd9cbd268d571c81aba7d280172b2 |
File details
Details for the file tspiral-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: tspiral-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a01a982daf05c21adc00376367799f5f289b653bd1d1d4d56ed6f16a00946e4e |
|
MD5 | 2fed14d3ec5498ad1d2f9b42f44c03c7 |
|
BLAKE2b-256 | edafdedbb2462e025eb57e02bb5b24428487b407fed26fc855f8e07eb8a63faf |