Package: tspiral
tspiralA 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.Overviewtspiral provides 4 optimized forecasting techniques:Recursive ForecastingLagged 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 ForecastingA 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 ForecastingMultiple recursive time series forecasters are fitted and combined on the final portion of the training data with a meta-learner.Rectified ForecastingMultiple direct time series forecasters are fitted and combined on the final portion of the training data with a meta-learner.GLOBAL and MULTIVARIATE time series forecasting are natively supported for all the forecasting methods available.For GLOBAL forecasting, use thegroupsparameter to specify the column of the input data that contains the group identifiers. For MULTIVARIATE forecasting, pass a target with multiple columns when calling fit.Installationpipinstall--upgradetspiralThe module depends only on NumPy, Pandas, and Scikit-Learn (>=0.24.2). Python 3.6 or above is supported.MediaHow to Improve Recursive Time Series ForecastingTime Series Forecasting with Feature Selection: Why you may need itForecast Time Series with Missing Values: Beyond Linear InterpolationTime Series Forecasting with Conformal Prediction Intervals: Scikit-Learn is All you NeedHitting Time Forecasting: The Other Way for Time Series Probabilistic ForecastingUsageRecursive Forecastingimportnumpyasnpfromsklearn.linear_modelimportRidgefromtspiral.forecastingimportForecastingCascadetimesteps=400e=np.random.normal(0,1,(timesteps,))y=np.concatenate([2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,])X=[[0]]*timesteps+[[1]]*timestepsmodel=ForecastingCascade(Ridge(),lags=range(1,24+1),groups=[0],).fit(X,y)forecasts=model.predict([[0]]*80+[[1]]*80)Direct Forecastingimportnumpyasnpfromsklearn.linear_modelimportRidgefromtspiral.forecastingimportForecastingChaintimesteps=400e=np.random.normal(0,1,(timesteps,))y=np.concatenate([2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,])X=[[0]]*timesteps+[[1]]*timestepsmodel=ForecastingChain(Ridge(),n_estimators=24,lags=range(1,24+1),groups=[0],).fit(X,y)forecasts=model.predict([[0]]*80+[[1]]*80)Stacking Forecastingimportnumpyasnpfromsklearn.linear_modelimportRidgefromsklearn.treeimportDecisionTreeRegressorfromtspiral.forecastingimportForecastingStackedtimesteps=400e=np.random.normal(0,1,(timesteps,))y=np.concatenate([2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,])X=[[0]]*timesteps+[[1]]*timestepsmodel=ForecastingStacked([Ridge(),DecisionTreeRegressor()],test_size=24*3,lags=range(1,24+1),groups=[0],).fit(X,y)forecasts=model.predict([[0]]*80+[[1]]*80)Rectified Forecastingimportnumpyasnpfromsklearn.linear_modelimportRidgefromsklearn.treeimportDecisionTreeRegressorfromtspiral.forecastingimportForecastingRectifiedtimesteps=400e=np.random.normal(0,1,(timesteps,))y=np.concatenate([2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,])X=[[0]]*timesteps+[[1]]*timestepsmodel=ForecastingRectified([Ridge(),DecisionTreeRegressor()],n_estimators=24*3,test_size=24*3,lags=range(1,24+1),groups=[0],).fit(X,y)forecasts=model.predict([[0]]*80+[[1]]*80)More examples in thenotebooks folder.