From e4371c5e39e75e5e7723e8eaa976325eb5fbac49 Mon Sep 17 00:00:00 2001 From: Raymond Vermaas Date: Sat, 9 Dec 2017 13:04:14 +0100 Subject: [PATCH 1/2] Fix compatiblity issues with FB Prophet 0.2.0 --- htsprophet/fitForecast.py | 11 +++++++---- htsprophet/hts.py | 22 +++++++++++----------- htsprophet/runHTS.py | 6 +++--- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/htsprophet/fitForecast.py b/htsprophet/fitForecast.py index 4f27582..590d148 100644 --- a/htsprophet/fitForecast.py +++ b/htsprophet/fitForecast.py @@ -23,8 +23,9 @@ #%% def fitForecast(y, h, sumMat, nodes, method, freq, include_history, cap, capF, changepoints, n_changepoints, \ - yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ - changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, boxcoxT, skipFitting): + yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, \ + holidays_prior_scale, changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, \ + boxcoxT, skipFitting): forecastsDict = {} mse = {} @@ -70,11 +71,11 @@ def fitForecast(y, h, sumMat, nodes, method, freq, include_history, cap, capF, c nodeToForecast = nodeToForecast.rename(columns = {nodeToForecast.columns[1] : 'y'}) if capF is None: growth = 'linear' - m = Prophet(growth, changepoints1, n_changepoints1, yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, \ + m = Prophet(growth, changepoints1, n_changepoints1, yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, \ holidays_prior_scale, changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples) else: growth = 'logistic' - m = Prophet(growth, changepoints, n_changepoints, yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, \ + m = Prophet(growth, changepoints, n_changepoints, yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, \ holidays_prior_scale, changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples) nodeToForecast['cap'] = cap1 m.fit(nodeToForecast) @@ -97,6 +98,8 @@ def fitForecast(y, h, sumMat, nodes, method, freq, include_history, cap, capF, c forecastsDict[node].trend = inv_boxcox(forecastsDict[node].trend, boxcoxT[node]) if "seasonal" in forecastsDict[node].columns.tolist(): forecastsDict[node].seasonal = inv_boxcox(forecastsDict[node].seasonal, boxcoxT[node]) + if "daily" in forecastsDict[node].columns.tolist(): + forecastsDict[node].daily = inv_boxcox(forecastsDict[node].daily, boxcoxT[node]) if "weekly" in forecastsDict[node].columns.tolist(): forecastsDict[node].weekly = inv_boxcox(forecastsDict[node].weekly, boxcoxT[node]) if "yearly" in forecastsDict[node].columns.tolist(): diff --git a/htsprophet/hts.py b/htsprophet/hts.py index 0a8f7b3..e0c89a5 100644 --- a/htsprophet/hts.py +++ b/htsprophet/hts.py @@ -26,7 +26,7 @@ #%% def hts(y, h = 1, nodes = [[2]], method='OLS', freq = 'D', transform = None, include_history = True, cap = None, capF = None, changepoints = None, \ - n_changepoints = 25, yearly_seasonality = 'auto', weekly_seasonality = 'auto', holidays = None, seasonality_prior_scale = 10.0, \ + n_changepoints = 25, yearly_seasonality = 'auto', weekly_seasonality = 'auto', daily_seasonality = 'auto', holidays = None, seasonality_prior_scale = 10.0, \ holidays_prior_scale = 10.0, changepoint_prior_scale = 0.05, mcmc_samples = 0, interval_width = 0.80, uncertainty_samples = 0, skipFitting = False, numThreads = 0): ''' Parameters @@ -211,32 +211,32 @@ def SummingMat(nodes): if numThreads != 0: pool = ThreadPool(numThreads) results = pool.starmap(fitForecast, zip([y.iloc[trainIndex, :]]*7, [len(testIndex)]*7, [sumMat]*7, [nodes]*7, methodList, [freq]*7, [include_history]*7, [cap]*7, [capF]*7, [changepoints]*7, [n_changepoints]*7, \ - [yearly_seasonality]*7, [weekly_seasonality]*7, [holidays]*7, [seasonality_prior_scale]*7, [holidays_prior_scale]*7,\ + [yearly_seasonality]*7, [weekly_seasonality]*7, [daily_seasonality]*7, [holidays]*7, [seasonality_prior_scale]*7, [holidays_prior_scale]*7,\ [changepoint_prior_scale]*7, [mcmc_samples]*7, [interval_width]*7, [uncertainty_samples]*7, [boxcoxT]*7, [skipFitting]*7)) pool.close() pool.join() ynew1, ynew2, ynew3, ynew4, ynew5, ynew6, ynew7 = results else: ynew1 = fitForecast(y.iloc[trainIndex, :], len(testIndex), sumMat, nodes, methodList[0], freq, include_history, cap, capF, changepoints, n_changepoints, \ - yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ + yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, boxcoxT, skipFitting) ynew2 = fitForecast(y.iloc[trainIndex, :], len(testIndex), sumMat, nodes, methodList[1], freq, include_history, cap, capF, changepoints, n_changepoints, \ - yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ + yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, boxcoxT, skipFitting) ynew3 = fitForecast(y.iloc[trainIndex, :], len(testIndex), sumMat, nodes, methodList[2], freq, include_history, cap, capF, changepoints, n_changepoints, \ - yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ + yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, boxcoxT, skipFitting) ynew4 = fitForecast(y.iloc[trainIndex, :], len(testIndex), sumMat, nodes, methodList[3], freq, include_history, cap, capF, changepoints, n_changepoints, \ - yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ + yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, boxcoxT, skipFitting) ynew5 = fitForecast(y.iloc[trainIndex, :], len(testIndex), sumMat, nodes, methodList[4], freq, include_history, cap, capF, changepoints, n_changepoints, \ - yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ + yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, boxcoxT, skipFitting) ynew6 = fitForecast(y.iloc[trainIndex, :], len(testIndex), sumMat, nodes, methodList[5], freq, include_history, cap, capF, changepoints, n_changepoints, \ - yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ + yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, boxcoxT, skipFitting) ynew7 = fitForecast(y.iloc[trainIndex, :], len(testIndex), sumMat, nodes, methodList[6], freq, include_history, cap, capF, changepoints, n_changepoints, \ - yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ + yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, boxcoxT, skipFitting) # for key in ynew1.keys(): @@ -253,7 +253,7 @@ def SummingMat(nodes): choices = [np.mean(MASE1), np.mean(MASE2), np.mean(MASE3), np.mean(MASE4), np.mean(MASE5), np.mean(MASE6), np.mean(MASE7)] choice = methodList[choices.index(min(choices))] ynew = fitForecast(y, h, sumMat, nodes, choice, freq, include_history, cap, capF, changepoints, n_changepoints, \ - yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ + yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, boxcoxT, skipFitting) print(choice) @@ -268,7 +268,7 @@ def SummingMat(nodes): i += 1 sumMat = SummingMat(nodes) ynew = fitForecast(y, h, sumMat, nodes, method, freq, include_history, cap, capF, changepoints, n_changepoints, \ - yearly_seasonality, weekly_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ + yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_prior_scale, holidays_prior_scale,\ changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, boxcoxT, skipFitting) ## # Inverse boxcox the data diff --git a/htsprophet/runHTS.py b/htsprophet/runHTS.py index f953080..3c7f1f8 100644 --- a/htsprophet/runHTS.py +++ b/htsprophet/runHTS.py @@ -67,6 +67,6 @@ # This output is a dictionary of dataframes, so you can do any further analysis that you may want. It also allows you to plot the forecasts. # Some functions I've made are: (1 means I'm plotting the total node) ## -plotNode(myDict, 1, h = 52, xlabel = "Week", ylabel = "Number of Sessions") -plotChild(myDict, 1, nodes, h = 52, xlabel = "Week", ylabel = "Number of Sessions", legend = ["Total","Air","Land","Sea"]) -plotNodeComponents(myDict, column = 1, holidays = holidays) \ No newline at end of file +plotNode(myDict, "Total", h = 52, xlabel = "Week", ylabel = "Number of Sessions") +plotChild(myDict, "Total", h = 52, xlabel = "Week", ylabel = "Number of Sessions") +plotNodeComponents(myDict, column = "Total", holidays = holidays) \ No newline at end of file From ee00c43e32205418a7f42b0a6ed50e797ce3dbec Mon Sep 17 00:00:00 2001 From: Raymond Vermaas Date: Sat, 9 Dec 2017 13:07:24 +0100 Subject: [PATCH 2/2] Bump version and fix dependency --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 788130c..6de1224 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup setup(name = 'htsprophet', - version = '0.1.0', + version = '0.1.1', description = "Creates Hierarchical Time Series Forecasts with Facebook's Prophet tool", url = "https://github.com/CollinRooney12/htsprophet", author = "Collin Rooney", @@ -16,6 +16,6 @@ 'matplotlib', 'pandas>=0.18.1', 'numpy', - 'fbprophet', + 'fbprophet>=0.2.0', 'scikit-learn>=0.18'], ) \ No newline at end of file