Package: tsforecasting
TSForecasting - Automated Time Series Forecasting FrameworkFramework ContextualizationTheTSForecastingproject 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 asSKLearn,H2O.ai,XGBoostand also univariate approaches of more classics methods such asProphetandAutoArima, 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 ofmodel_configurationsdictionary, 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 ToolsMajor frameworks used to built this project:SklearnH2O.aiXGBoostAutoArimaProphetPerformance Evaluation StructureThe 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 itThe source code is currently hosted on GitHub at:https://github.com/TsLu1s/TSForecastingBinary installer for the latest released version is available at the Python Package Index (PyPI).InstallationTo install this package from Pypi repository run the following command:pip install tsforecastingUsage Examples1. TSForecasting - Automated Time Series ForecastingThe 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 toDateandy, 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 paramatermodels:list, options are the following:RandomForestExtraTreesGBRKNNGeneralizedLRXGBoostH2O_AutoMLAutoArimaProphethparameters: 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 isMAE(Mean Absolute Error), other options areMAPE(Mean Absolute Percentage Error) andMSE(Mean Squared Error);Thefit_forecastmethod set the default parameters for fitting and comparison of all segmented windows for each selected and configurated model. After implementation, thehistorymethod agregates the returning variablesfit_performancecontaining every detailed measure of eachwindowiteration predicted value andfit_predictionsmeasuring all segmentedwindowiterations performance.Theforecastmethod forecasts the future values based on the previously predefined best performing model.fromtsforecasting.forecastingimportTSForecastingfromtsforecasting.parametersimportmodel_configurationsimportpandasaspdimportwarningswarnings.filterwarnings("ignore",category=Warning)#-> For a clean consoleimporth2oh2o.init()# -> Run only if using H2O_AutoML models## Dataframe Loadingdata=pd.read_csv('csv_directory_path')data=data.rename(columns={'DateTime_Column':'Date','Target_Name_Column':'y'})data=data[['Date',"y"]]## Get Models Hyperparameters Configurationsparameters=model_configurations()print(parameters)# Customization Hyperparameters Exampleparameters["RandomForest"]["n_estimators"]=200parameters["KNN"]["n_neighbors"]=5parameters["Prophet"]["seasonality_mode"]='multiplicative'parameters["H2O_AutoML"]["max_runtime_secs"]=90## Fit Forecasting Evaluationtsf=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,1mometric="MAE"# MAPE, MSE)tsf=tsf.fit_forecast(dataset=data)# Get Fit Historyfit_predictions,fit_performance=tsf.history()## Forecastforecast=tsf.forecast()2. TSForecasting - Extra Auxiliar MethodsTheengin_datemethod 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 parameterdrop=True.Themultivariable_lagmethod creats all the past lags related to the targetyfeature automatically (in accordance torange_lagsparameter) and adds each constructed column into the dataset.# Feature Engineeringfromtsforecasting.treatmentimportTreatmenttr=Treatment()data=tr.engin_date(dataset=data,drop=False)data=tr.multivariable_lag(dataset=data,range_lags=[1,10],drop_na=True)LicenseDistributed under the MIT License. SeeLICENSEfor more information.ContactLuis Santos -LinkedIn