Skip to main content

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.

recursive-standard

Which in a compact way we can summarize in:

recursive-compact

  • Direct Forecasting

A scikit-learn compatible regressor is fitted on the lagged data for each time step to forecast.

direct

  • Stacking Forecasting

Multiple recursive time series forecasters are fitted and combined on the final portion of the training data with a meta-learner.

stacked

  • Rectified Forecasting

Multiple recursive time series forecasters are fitted on different sliding window training bunches. Forecasts are adjusted and combined fitting a meta-learner for each forecasting step.

rectify

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.

Usage

  • Recursive Forecasting
import numpy as np
from sklearn.linear_model import Ridge
from tsprial.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(np.arange(len(y)), y)
forecasts = model.predict(np.arange(24*3))
  • Direct Forecasting
import numpy as np
from sklearn.linear_model import Ridge
from tsprial.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(np.arange(len(y)), 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 tsprial.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(np.arange(len(y)), y)
forecasts = model.predict(np.arange(24*3))
  • Rectified Forecasting
import numpy as np
from sklearn.linear_model import Ridge
from tsprial.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(),
    n_estimators=200,
    test_size=24*3,
    lags=range(1,24+1),
    use_exog=False
)
model.fit(np.arange(len(y)), 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

tspiral-0.1.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

tspiral-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file tspiral-0.1.0.tar.gz.

File metadata

  • Download URL: tspiral-0.1.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for tspiral-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0db8a3133ef8632f5c63cc2595dc7f4f687ea20d1b0868a07677f0746e5c2d5
MD5 8e0eadfaf9e5f1b984e6a318b15824bc
BLAKE2b-256 fb9643e3367b57e4017a9a318789b040f035e8e66e7df26f503cc08dc63dd14e

See more details on using hashes here.

File details

Details for the file tspiral-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tspiral-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for tspiral-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c89a0d557a3947dad7d22aba6317ddf21dc4cfc75439435c4556864b614c89b4
MD5 fddd9b8fc088c87e913a89ae678ae75f
BLAKE2b-256 baee09e8786dc96c55734b5e96c44e8aeba5364c6adde997f2a917a422169db5

See more details on using hashes here.

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