Code Monkey home page Code Monkey logo

tspiral's Introduction

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.

Media

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(None, 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(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 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(None, 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(None, y)
forecasts = model.predict(np.arange(24*3))

More examples in the notebooks folder.

tspiral's People

Contributors

cerlymarco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.