implemented disabling calculation of uncertainties if uncertainty_samples is 0

This commit is contained in:
Alexander Gawrilow 2019-07-23 10:59:28 +02:00 committed by Ben Letham
parent 480b67b8fe
commit 0679e69dba

View file

@ -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):