Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Calculate seasonal components
self.forecast = self.model.predict_seasonal_components(df_y)
else:
# Prepare the seasonality data frame
start = pd.to_datetime('2017-01-01 0000')
period = self.model.seasonalities[self.seasonality]['period']
end = start + pd.Timedelta(days=period)
# plot_points = 200
# plot_points is used instead of period below in fbprophet/forecaster.py.
# However, it seems to make more sense to use period given the expected usage in Qlik
intervals = pd.to_datetime(np.linspace(start.value, end.value, period))
df_x = plot.seasonality_plot_df(self.model, intervals)
# Calculate seasonal components
self.forecast = self.model.predict_seasonal_components(df_x)
# Set the correct sort order for the response
try:
self.forecast = self.forecast.reindex(self.sort_order.index)
except AttributeError:
pass
# For standard forecast the output rows equal the input rows
else:
# Prepare the forecast
self.forecast = self.model.predict(self.future_df)
# For return=y_then_yhat[_upper / _lower] we return y values followed by relevant results for the forecast periods
def _forecast(self):
"""
Execute the forecast algorithm according to the request type
"""
# If this is a seasonality request, we need to return the relevant seasonlity component
if self.is_seasonality_request:
if self.seasonality == 'weekly':
# Prepare the seasonality data frame
# Parameter start needs to be any arbitrary week starting on a Sunday
days = (pd.date_range(start='2017-01-01', periods=7) + pd.Timedelta(days=self.weekly_start))
df_w = plot.seasonality_plot_df(self.model, days)
# Calculate seasonal components
self.forecast = self.model.predict_seasonal_components(df_w)
elif self.seasonality == 'yearly':
# Prepare the seasonality data frame
# Parameter start needs to be 1st January for any arbitrary year
days = (pd.date_range(start='2017-01-01', periods=365) + pd.Timedelta(days=self.yearly_start))
df_y = plot.seasonality_plot_df(self.model, days)
# Calculate seasonal components
self.forecast = self.model.predict_seasonal_components(df_y)
else:
# Prepare the seasonality data frame
start = pd.to_datetime('2017-01-01 0000')