{"id":15787136,"url":"https://github.com/cerlymarco/tspiral","last_synced_at":"2025-04-07T07:15:04.399Z","repository":{"id":45571945,"uuid":"513146360","full_name":"cerlymarco/tspiral","owner":"cerlymarco","description":"A python package for time series forecasting with scikit-learn estimators.","archived":false,"fork":false,"pushed_at":"2024-04-04T14:53:33.000Z","size":2860,"stargazers_count":160,"open_issues_count":0,"forks_count":20,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-11T21:43:40.844Z","etag":null,"topics":["autoregressive-forecasters","autoregressive-modeling","direct-forecasting","exogenous-predictors","forecasting","multivariate-forecasting","multivariate-timeseries","python","recursive-forecasting","scikit-learn","time-series","timeseries","timeseries-forecasting"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cerlymarco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-12T13:07:38.000Z","updated_at":"2024-10-08T01:06:24.000Z","dependencies_parsed_at":"2023-09-22T07:05:44.706Z","dependency_job_id":"f4a0b2c7-534c-46f1-899b-52f576009988","html_url":"https://github.com/cerlymarco/tspiral","commit_stats":{"total_commits":23,"total_committers":2,"mean_commits":11.5,"dds":"0.13043478260869568","last_synced_commit":"73823aab08a7d3e2633efb1a3ac4924d197cd03a"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerlymarco%2Ftspiral","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerlymarco%2Ftspiral/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerlymarco%2Ftspiral/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerlymarco%2Ftspiral/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cerlymarco","download_url":"https://codeload.github.com/cerlymarco/tspiral/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608153,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoregressive-forecasters","autoregressive-modeling","direct-forecasting","exogenous-predictors","forecasting","multivariate-forecasting","multivariate-timeseries","python","recursive-forecasting","scikit-learn","time-series","timeseries","timeseries-forecasting"],"created_at":"2024-10-04T21:05:34.220Z","updated_at":"2025-04-07T07:15:04.373Z","avatar_url":"https://github.com/cerlymarco.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tspiral\nA python package for time series forecasting with scikit-learn estimators.\n\ntspiral 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. \n\n## Overview\n\ntspiral provides 4 optimized forecasting techniques:\n\n- **Recursive Forecasting** \n\nLagged 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.\n\n![recursive-standard](https://raw.githubusercontent.com/cerlymarco/tspiral/master/imgs/recursive-standard.PNG)\n\nWhich in a compact way we can summarize in:\n\n![recursive-compact](https://raw.githubusercontent.com/cerlymarco/tspiral/master/imgs/recursive-compact.PNG)\n\n- **Direct Forecasting** \n\nA scikit-learn compatible regressor is fitted on the lagged data for each time step to forecast. \n\n![direct](https://raw.githubusercontent.com/cerlymarco/tspiral/master/imgs/direct.PNG)\n\nWhich in a compact way we can summarize in:\n\n![direct-compact](https://raw.githubusercontent.com/cerlymarco/tspiral/master/imgs/direct-compact.png)\n\nIt's also possible to mix recursive and direct forecasting by predicting directly some future horizons while using recursive on the remaining. \n\n![directmix-compact](https://raw.githubusercontent.com/cerlymarco/tspiral/master/imgs/directmix-compact.png)\n\n- **Stacking Forecasting** \n\nMultiple recursive time series forecasters are fitted and combined on the final portion of the training data with a meta-learner.\n\n![stacked](https://raw.githubusercontent.com/cerlymarco/tspiral/master/imgs/stacked.PNG)\n\n- **Rectified Forecasting** \n\nMultiple direct time series forecasters are fitted and combined on the final portion of the training data with a meta-learner.\n\n![rectify](https://raw.githubusercontent.com/cerlymarco/tspiral/master/imgs/rectify.PNG)\n\n**GLOBAL and MULTIVARIATE time series forecasting are natively supported for all the forecasting methods available.** For GLOBAL forecasting, use the `groups` parameter 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. \n\n## Installation\n```shell\npip install --upgrade tspiral\n```\nThe module depends only on NumPy, Pandas, and Scikit-Learn (\u003e=0.24.2). Python 3.6 or above is supported.\n\n## Media\n\n- [How to Improve Recursive Time Series Forecasting](https://medium.com/towards-data-science/how-to-improve-recursive-time-series-forecasting-ff5b90a98eeb)\n- [Time Series Forecasting with Feature Selection: Why you may need it](https://medium.com/towards-data-science/time-series-forecasting-with-feature-selection-why-you-may-need-it-696b23ecc329)\n- [Forecast Time Series with Missing Values: Beyond Linear Interpolation](https://medium.com/towards-data-science/forecast-time-series-with-missing-values-beyond-linear-interpolation-2f2adf0a0cba)\n- [Time Series Forecasting with Conformal Prediction Intervals: Scikit-Learn is All you Need](https://medium.com/towards-data-science/time-series-forecasting-with-conformal-prediction-intervals-scikit-learn-is-all-you-need-4b68143a027a)\n- [Hitting Time Forecasting: The Other Way for Time Series Probabilistic Forecasting](https://medium.com/towards-data-science/hitting-time-forecasting-the-other-way-for-time-series-probabilistic-forecasting-6c3b6496c353)\n- [Hitchhiker’s Guide to MLOps for Time Series Forecasting with Sklearn](https://medium.com/towards-data-science/hitchhikers-guide-to-mlops-for-time-series-forecasting-with-sklearn-d5d9728095a7)\n\n## Usage\n\n- **Recursive Forecasting** \n```python\nimport numpy as np\nfrom sklearn.linear_model import Ridge\nfrom tspiral.forecasting import ForecastingCascade\ntimesteps = 400\ne = np.random.normal(0,1, (timesteps,))\ny = np.concatenate([\n    2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,\n    2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,\n])\nX = [[0]]*timesteps+[[1]]*timesteps \nmodel = ForecastingCascade(\n    Ridge(),\n    lags=range(1,24+1),\n    groups=[0],\n).fit(X, y)\nforecasts = model.predict([[0]]*80+[[1]]*80)\n```\n\n- **Direct Forecasting** \n```python\nimport numpy as np\nfrom sklearn.linear_model import Ridge\nfrom tspiral.forecasting import ForecastingChain\ntimesteps = 400\ne = np.random.normal(0,1, (timesteps,))\ny = np.concatenate([\n    2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,\n    2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,\n])\nX = [[0]]*timesteps+[[1]]*timesteps \nmodel = ForecastingChain(\n    Ridge(),\n    n_estimators=24,\n    lags=range(1,24+1),\n    groups=[0],\n).fit(X, y)\nforecasts = model.predict([[0]]*80+[[1]]*80)\n```\n\n- **Stacking Forecasting** \n```python\nimport numpy as np\nfrom sklearn.linear_model import Ridge\nfrom sklearn.tree import DecisionTreeRegressor\nfrom tspiral.forecasting import ForecastingStacked\ntimesteps = 400\ne = np.random.normal(0,1, (timesteps,))\ny = np.concatenate([\n    2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,\n    2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,\n])\nX = [[0]]*timesteps+[[1]]*timesteps \nmodel = ForecastingStacked(\n    [Ridge(), DecisionTreeRegressor()],\n    test_size=24*3,\n    lags=range(1,24+1),\n    groups=[0],\n).fit(X, y)\nforecasts = model.predict([[0]]*80+[[1]]*80)\n```\n\n- **Rectified Forecasting** \n```python\nimport numpy as np\nfrom sklearn.linear_model import Ridge\nfrom sklearn.tree import DecisionTreeRegressor\nfrom tspiral.forecasting import ForecastingRectified\ntimesteps = 400\ne = np.random.normal(0,1, (timesteps,))\ny = np.concatenate([\n    2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,\n    2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,\n])\nX = [[0]]*timesteps+[[1]]*timesteps  \nmodel = ForecastingRectified(\n    [Ridge(), DecisionTreeRegressor()],\n    n_estimators=24*3,\n    test_size=24*3,\n    lags=range(1,24+1),\n    groups=[0],\n).fit(X, y)\nforecasts = model.predict([[0]]*80+[[1]]*80)\n```\n\nMore examples in the [notebooks folder](https://github.com/cerlymarco/tspiral/tree/main/notebooks).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcerlymarco%2Ftspiral","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcerlymarco%2Ftspiral","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcerlymarco%2Ftspiral/lists"}