tsforecasting


Nametsforecasting JSON
Version 1.2.76 PyPI version JSON
download
home_pagehttps://github.com/TsLu1s/TSForecasting
SummaryTSForecasting is an Automated Time Series Forecasting Framework
upload_time2023-11-27 22:15:19
maintainer
docs_urlNone
authorLuís Santos
requires_python
licenseMIT
keywords data science machine learning time series forecasting automated time series multivariate time series univariate time series automated machine learning automl
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <br>
<p align="center">
  <h2 align="center"> TSForecasting - Automated Time Series Forecasting Framework
  <br>
  
## Framework Contextualization <a name = "ta"></a>

The `TSForecasting` project constitutes an complete and integrated pipeline to Automate Time Series Forecasting applications through the implementation of multivariate approaches integrating regression models referring to modules such as `SKLearn`, `H2O.ai`, `XGBoost` and also univariate approaches of more classics methods such as `Prophet` and `AutoArima`, this following an 'Expanding Window' performance evaluation.

The architecture design includes five main sections, these being: data preprocessing, feature engineering, hyperparameter optimization, forecast ensembling and forecasting method selection which are organized and customizable in a pipeline structure.

This project aims at providing the following application capabilities:

* General applicability on tabular datasets: The developed forecasting procedures are applicable on any data table associated with any Time Series Forecasting scopes.

* Hyperparameter optimization and customization: It provides full configuration for each model hyperparameter through the customization of `model_configurations` dictionary, allowing optimal performance to be obtained for any use case.
    
* Robustness and improvement of predictive results: The implementation of the TSForecasting pipeline aims to improve the predictive performance directly associated with the application of the best performing forecasting method. 
   
#### Main Development Tools <a name = "pre1"></a>

Major frameworks used to built this project: 

* [Sklearn](https://scikit-learn.org/stable/)
* [H2O.ai](https://docs.h2o.ai/h2o/latest-stable/h2o-docs/automl.html)
* [XGBoost](https://xgboost.readthedocs.io/en/stable/)
* [AutoArima](https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.auto_arima.html)
* [Prophet](https://facebook.github.io/prophet/docs/quick_start.html#python-api)
    
## Performance Evaluation Structure <a name = "ta"></a>

<p align="center">
  <img src="https://i.ibb.co/ctYj6tt/Expanding-Window-TSF.png" align="center" width="450" height="350" />
</p>  
    
The Expanding Window evaluation technique is a temporary approximation on the real value of the time series data. 
The first test segment is selected according to the train length and then it's forecasted in accordance with forecast size.
The starting position of the subsequent segment is set in direct relation to the sliding window size, this meaning, if the
sliding size is equal to the forecast size, each next segment starts at the end of the previous.
This process is repeated until all time series data gets segmented and it uses all the iterations and observations
to construct an aggregated and robust performance analysis to each predicted point.

## Where to get it <a name = "ta"></a>

The source code is currently hosted on GitHub at: https://github.com/TsLu1s/TSForecasting

Binary installer for the latest released version is available at the Python Package Index (PyPI).   

## Installation  

To install this package from Pypi repository run the following command:

```
pip install tsforecasting
```

# Usage Examples
    
## 1. TSForecasting - Automated Time Series Forecasting
    
The first needed step after importing the package is to load a dataset and define your DataTime (`datetime64[ns]` type) and Target column to be predicted, then rename them to `Date` and `y`, respectively.
The following step is to define your future running pipeline parameters variables, these being:
* train_size: Length of Train data in which will be applied the first Expanding Window iteration;  
* forecast_size: Full length of test/future ahead predictions;
* sliding_size: Length of sliding window, sliding_size>=forecast_size is suggested;
* models: Select all the models intented to ensemble to evaluation. To fit and compare predictive performance of available models set them in paramater `models:list`, options are the following:
  * `RandomForest`
  * `ExtraTrees`
  * `GBR`
  * `KNN`
  * `GeneralizedLR`
  * `XGBoost`
  * `H2O_AutoML`
  * `AutoArima`
  * `Prophet`
* hparameters: Nested dictionary in which are contained all models and specific hyperparameters configurations. Feel free to customize each model as you see fit (customization example shown bellow); 
* granularity: Valid interval of periods correlated to data -> 1m,30m,1h,1d,1wk,1mo (default='1d');
* metric: Default predictive evaluation metric is `MAE` (Mean Absolute Error), other options are `MAPE` (Mean Absolute Percentage Error) and `MSE`
(Mean Squared Error);
 
The `fit_forecast` method set the default parameters for fitting and comparison of all segmented windows for each selected and configurated model. After implementation, the `history` method agregates the returning variables `fit_performance` containing every detailed measure of each `window` iteration predicted value and `fit_predictions` measuring all segmented `window` iterations performance.

The `forecast` method forecasts the future values based on the previously predefined best performing model.
        
```py

from tsforecasting.forecasting import TSForecasting
from tsforecasting.parameters import model_configurations
import pandas as pd
import warnings
warnings.filterwarnings("ignore", category=Warning) #-> For a clean console
import h2o

h2o.init() # -> Run only if using H2O_AutoML models   

## Dataframe Loading
data = pd.read_csv('csv_directory_path') 
data = data.rename(columns={'DateTime_Column': 'Date','Target_Name_Column':'y'})
data = data[['Date',"y"]]
    
## Get Models Hyperparameters Configurations
parameters = model_configurations()
print(parameters)

# Customization Hyperparameters Example
parameters["RandomForest"]["n_estimators"] = 200
parameters["KNN"]["n_neighbors"] = 5
parameters["Prophet"]["seasonality_mode"] = 'multiplicative'
parameters["H2O_AutoML"]["max_runtime_secs"] = 90

## Fit Forecasting Evaluation
tsf = TSForecasting(train_size = 0.95,
                    forecast_size = 15,
                    sliding_size = 15,
                    models = ['RandomForest','ExtraTrees', 'GBR', 'KNN', 'GeneralizedLR',
                              'XGBoost', 'AutoArima','Prophet','H2O_AutoML'],
                    hparameters = parameters,
                    granularity = "1h", # 1m,30m,1h,1d,1wk,1mo
                    metric = "MAE"      # MAPE, MSE
                    )
tsf = tsf.fit_forecast(dataset = data)

# Get Fit History
fit_predictions, fit_performance = tsf.history()

## Forecast
forecast = tsf.forecast()

```  

## 2. TSForecasting - Extra Auxiliar Methods
    
The `engin_date` method converts and transforms columns of Datetime type into additional columns (Year, Day of the  Year, Season, Month, Day of the month, Day of the week, Weekend, Hour, Minute, Second) which will be added by association to the input dataset and subsequently deletes the original column if parameter `drop`=`True`.

The `multivariable_lag` method creats all the past lags related to the target `y` feature automatically (in accordance to `range_lags` parameter) and adds each constructed column into the dataset.
 
```py   

# Feature Engineering 

from tsforecasting.treatment import Treatment

tr = Treatment()

data = tr.engin_date(dataset = data,
                     drop = False) 

data = tr.multivariable_lag(dataset = data,
                            range_lags = [1,10],
                            drop_na = True)    
```
    
## License

Distributed under the MIT License. See [LICENSE](https://github.com/TsLu1s/TSForecasting/blob/main/LICENSE) for more information.

## Contact 
 
Luis Santos - [LinkedIn](https://www.linkedin.com/in/lu%C3%ADsfssantos/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TsLu1s/TSForecasting",
    "name": "tsforecasting",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "data science,machine learning,time series forecasting,automated time series,multivariate time series,univariate time series,automated machine learning,automl",
    "author": "Lu\u00eds Santos",
    "author_email": "luisf_ssantos@hotmail.com",
    "download_url": "",
    "platform": null,
    "description": "<br>\r\n<p align=\"center\">\r\n  <h2 align=\"center\"> TSForecasting - Automated Time Series Forecasting Framework\r\n  <br>\r\n  \r\n## Framework Contextualization <a name = \"ta\"></a>\r\n\r\nThe `TSForecasting` project constitutes an complete and integrated pipeline to Automate Time Series Forecasting applications through the implementation of multivariate approaches integrating regression models referring to modules such as `SKLearn`, `H2O.ai`, `XGBoost` and also univariate approaches of more classics methods such as `Prophet` and `AutoArima`, this following an 'Expanding Window' performance evaluation.\r\n\r\nThe architecture design includes five main sections, these being: data preprocessing, feature engineering, hyperparameter optimization, forecast ensembling and forecasting method selection which are organized and customizable in a pipeline structure.\r\n\r\nThis project aims at providing the following application capabilities:\r\n\r\n* General applicability on tabular datasets: The developed forecasting procedures are applicable on any data table associated with any Time Series Forecasting scopes.\r\n\r\n* Hyperparameter optimization and customization: It provides full configuration for each model hyperparameter through the customization of `model_configurations` dictionary, allowing optimal performance to be obtained for any use case.\r\n    \r\n* Robustness and improvement of predictive results: The implementation of the TSForecasting pipeline aims to improve the predictive performance directly associated with the application of the best performing forecasting method. \r\n   \r\n#### Main Development Tools <a name = \"pre1\"></a>\r\n\r\nMajor frameworks used to built this project: \r\n\r\n* [Sklearn](https://scikit-learn.org/stable/)\r\n* [H2O.ai](https://docs.h2o.ai/h2o/latest-stable/h2o-docs/automl.html)\r\n* [XGBoost](https://xgboost.readthedocs.io/en/stable/)\r\n* [AutoArima](https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.auto_arima.html)\r\n* [Prophet](https://facebook.github.io/prophet/docs/quick_start.html#python-api)\r\n    \r\n## Performance Evaluation Structure <a name = \"ta\"></a>\r\n\r\n<p align=\"center\">\r\n  <img src=\"https://i.ibb.co/ctYj6tt/Expanding-Window-TSF.png\" align=\"center\" width=\"450\" height=\"350\" />\r\n</p>  \r\n    \r\nThe Expanding Window evaluation technique is a temporary approximation on the real value of the time series data. \r\nThe first test segment is selected according to the train length and then it's forecasted in accordance with forecast size.\r\nThe starting position of the subsequent segment is set in direct relation to the sliding window size, this meaning, if the\r\nsliding size is equal to the forecast size, each next segment starts at the end of the previous.\r\nThis process is repeated until all time series data gets segmented and it uses all the iterations and observations\r\nto construct an aggregated and robust performance analysis to each predicted point.\r\n\r\n## Where to get it <a name = \"ta\"></a>\r\n\r\nThe source code is currently hosted on GitHub at: https://github.com/TsLu1s/TSForecasting\r\n\r\nBinary installer for the latest released version is available at the Python Package Index (PyPI).   \r\n\r\n## Installation  \r\n\r\nTo install this package from Pypi repository run the following command:\r\n\r\n```\r\npip install tsforecasting\r\n```\r\n\r\n# Usage Examples\r\n    \r\n## 1. TSForecasting - Automated Time Series Forecasting\r\n    \r\nThe first needed step after importing the package is to load a dataset and define your DataTime (`datetime64[ns]` type) and Target column to be predicted, then rename them to `Date` and `y`, respectively.\r\nThe following step is to define your future running pipeline parameters variables, these being:\r\n* train_size: Length of Train data in which will be applied the first Expanding Window iteration;  \r\n* forecast_size: Full length of test/future ahead predictions;\r\n* sliding_size: Length of sliding window, sliding_size>=forecast_size is suggested;\r\n* models: Select all the models intented to ensemble to evaluation. To fit and compare predictive performance of available models set them in paramater `models:list`, options are the following:\r\n  * `RandomForest`\r\n  * `ExtraTrees`\r\n  * `GBR`\r\n  * `KNN`\r\n  * `GeneralizedLR`\r\n  * `XGBoost`\r\n  * `H2O_AutoML`\r\n  * `AutoArima`\r\n  * `Prophet`\r\n* hparameters: Nested dictionary in which are contained all models and specific hyperparameters configurations. Feel free to customize each model as you see fit (customization example shown bellow); \r\n* granularity: Valid interval of periods correlated to data -> 1m,30m,1h,1d,1wk,1mo (default='1d');\r\n* metric: Default predictive evaluation metric is `MAE` (Mean Absolute Error), other options are `MAPE` (Mean Absolute Percentage Error) and `MSE`\r\n(Mean Squared Error);\r\n \r\nThe `fit_forecast` method set the default parameters for fitting and comparison of all segmented windows for each selected and configurated model. After implementation, the `history` method agregates the returning variables `fit_performance` containing every detailed measure of each `window` iteration predicted value and `fit_predictions` measuring all segmented `window` iterations performance.\r\n\r\nThe `forecast` method forecasts the future values based on the previously predefined best performing model.\r\n        \r\n```py\r\n\r\nfrom tsforecasting.forecasting import TSForecasting\r\nfrom tsforecasting.parameters import model_configurations\r\nimport pandas as pd\r\nimport warnings\r\nwarnings.filterwarnings(\"ignore\", category=Warning) #-> For a clean console\r\nimport h2o\r\n\r\nh2o.init() # -> Run only if using H2O_AutoML models   \r\n\r\n## Dataframe Loading\r\ndata = pd.read_csv('csv_directory_path') \r\ndata = data.rename(columns={'DateTime_Column': 'Date','Target_Name_Column':'y'})\r\ndata = data[['Date',\"y\"]]\r\n    \r\n## Get Models Hyperparameters Configurations\r\nparameters = model_configurations()\r\nprint(parameters)\r\n\r\n# Customization Hyperparameters Example\r\nparameters[\"RandomForest\"][\"n_estimators\"] = 200\r\nparameters[\"KNN\"][\"n_neighbors\"] = 5\r\nparameters[\"Prophet\"][\"seasonality_mode\"] = 'multiplicative'\r\nparameters[\"H2O_AutoML\"][\"max_runtime_secs\"] = 90\r\n\r\n## Fit Forecasting Evaluation\r\ntsf = TSForecasting(train_size = 0.95,\r\n                    forecast_size = 15,\r\n                    sliding_size = 15,\r\n                    models = ['RandomForest','ExtraTrees', 'GBR', 'KNN', 'GeneralizedLR',\r\n                              'XGBoost', 'AutoArima','Prophet','H2O_AutoML'],\r\n                    hparameters = parameters,\r\n                    granularity = \"1h\", # 1m,30m,1h,1d,1wk,1mo\r\n                    metric = \"MAE\"      # MAPE, MSE\r\n                    )\r\ntsf = tsf.fit_forecast(dataset = data)\r\n\r\n# Get Fit History\r\nfit_predictions, fit_performance = tsf.history()\r\n\r\n## Forecast\r\nforecast = tsf.forecast()\r\n\r\n```  \r\n\r\n## 2. TSForecasting - Extra Auxiliar Methods\r\n    \r\nThe `engin_date` method converts and transforms columns of Datetime type into additional columns (Year, Day of the  Year, Season, Month, Day of the month, Day of the week, Weekend, Hour, Minute, Second) which will be added by association to the input dataset and subsequently deletes the original column if parameter `drop`=`True`.\r\n\r\nThe `multivariable_lag` method creats all the past lags related to the target `y` feature automatically (in accordance to `range_lags` parameter) and adds each constructed column into the dataset.\r\n \r\n```py   \r\n\r\n# Feature Engineering \r\n\r\nfrom tsforecasting.treatment import Treatment\r\n\r\ntr = Treatment()\r\n\r\ndata = tr.engin_date(dataset = data,\r\n                     drop = False) \r\n\r\ndata = tr.multivariable_lag(dataset = data,\r\n                            range_lags = [1,10],\r\n                            drop_na = True)    \r\n```\r\n    \r\n## License\r\n\r\nDistributed under the MIT License. See [LICENSE](https://github.com/TsLu1s/TSForecasting/blob/main/LICENSE) for more information.\r\n\r\n## Contact \r\n \r\nLuis Santos - [LinkedIn](https://www.linkedin.com/in/lu%C3%ADsfssantos/)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "TSForecasting is an Automated Time Series Forecasting Framework",
    "version": "1.2.76",
    "project_urls": {
        "Homepage": "https://github.com/TsLu1s/TSForecasting"
    },
    "split_keywords": [
        "data science",
        "machine learning",
        "time series forecasting",
        "automated time series",
        "multivariate time series",
        "univariate time series",
        "automated machine learning",
        "automl"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38433af5fd1b1a5cf6c48c8f8ec84f09439776ed20a87d075f762469c2228579",
                "md5": "e1956726bef8eafce907280f7e4ce23f",
                "sha256": "f161f14939942486c4db35e49a71e3ba12bfa82bc2756bdb726e87be8e096b98"
            },
            "downloads": -1,
            "filename": "tsforecasting-1.2.76-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e1956726bef8eafce907280f7e4ce23f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 16329,
            "upload_time": "2023-11-27T22:15:19",
            "upload_time_iso_8601": "2023-11-27T22:15:19.701552Z",
            "url": "https://files.pythonhosted.org/packages/38/43/3af5fd1b1a5cf6c48c8f8ec84f09439776ed20a87d075f762469c2228579/tsforecasting-1.2.76-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-27 22:15:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TsLu1s",
    "github_project": "TSForecasting",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "tsforecasting"
}
        
Elapsed time: 0.17428s