From 0679e69dbaee33b5ae379a62e8ce03aa3dd67b8e Mon Sep 17 00:00:00 2001 From: Alexander Gawrilow Date: Tue, 23 Jul 2019 10:59:28 +0200 Subject: [PATCH] implemented disabling calculation of uncertainties if uncertainty_samples is 0 --- python/fbprophet/forecaster.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/python/fbprophet/forecaster.py b/python/fbprophet/forecaster.py index 29240e9..905aff3 100644 --- a/python/fbprophet/forecaster.py +++ b/python/fbprophet/forecaster.py @@ -75,7 +75,8 @@ class Prophet(object): model. If mcmc.samples>0, this will be integrated over all model parameters, which will include uncertainty in seasonality. uncertainty_samples: Number of simulated draws used to estimate - uncertainty intervals. + uncertainty intervals. Settings this value to 0 or False will disable + uncertainty estimation and speed up the calculation. """ def __init__( @@ -1173,7 +1174,10 @@ class Prophet(object): df['trend'] = self.predict_trend(df) seasonal_components = self.predict_seasonal_components(df) - intervals = self.predict_uncertainty(df) + if self.uncertainty_samples: + intervals = self.predict_uncertainty(df) + else: + intervals = None # Drop columns except ds, cap, floor, and trend cols = ['ds', 'trend'] @@ -1289,8 +1293,9 @@ class Prophet(object): seasonal_features, _, component_cols, _ = ( self.make_all_seasonality_features(df) ) - lower_p = 100 * (1.0 - self.interval_width) / 2 - upper_p = 100 * (1.0 + self.interval_width) / 2 + if self.uncertainty_samples: + lower_p = 100 * (1.0 - self.interval_width) / 2 + upper_p = 100 * (1.0 + self.interval_width) / 2 X = seasonal_features.values data = {} @@ -1301,12 +1306,13 @@ class Prophet(object): if component in self.component_modes['additive']: comp *= self.y_scale data[component] = np.nanmean(comp, axis=1) - data[component + '_lower'] = np.nanpercentile( - comp, lower_p, axis=1, - ) - data[component + '_upper'] = np.nanpercentile( - comp, upper_p, axis=1, - ) + if self.uncertainty_samples: + data[component + '_lower'] = np.nanpercentile( + comp, lower_p, axis=1, + ) + data[component + '_upper'] = np.nanpercentile( + comp, upper_p, axis=1, + ) return pd.DataFrame(data) def sample_posterior_predictive(self, df):