Predict using the prophet model. Parameters ---------- df: pd.DataFrame with dates for predictions (column ds), and capacity (column cap) if logistic growth. If not provided, predictions are made on the history. vectorized: Whether to use a ve
(self, df: pd.DataFrame = None, vectorized: bool = True)
| 1247 | return self |
| 1248 | |
| 1249 | def predict(self, df: pd.DataFrame = None, vectorized: bool = True) -> pd.DataFrame: |
| 1250 | """Predict using the prophet model. |
| 1251 | |
| 1252 | Parameters |
| 1253 | ---------- |
| 1254 | df: pd.DataFrame with dates for predictions (column ds), and capacity |
| 1255 | (column cap) if logistic growth. If not provided, predictions are |
| 1256 | made on the history. |
| 1257 | vectorized: Whether to use a vectorized method to compute uncertainty intervals. Suggest using |
| 1258 | True (the default) for much faster runtimes in most cases, |
| 1259 | except when (growth = 'logistic' and mcmc_samples > 0). |
| 1260 | |
| 1261 | Returns |
| 1262 | ------- |
| 1263 | A pd.DataFrame with the forecast components. |
| 1264 | """ |
| 1265 | if self.history is None: |
| 1266 | raise Exception('Model has not been fit.') |
| 1267 | |
| 1268 | if df is None: |
| 1269 | df = self.history.copy() |
| 1270 | else: |
| 1271 | if df.shape[0] == 0: |
| 1272 | raise ValueError('Dataframe has no rows.') |
| 1273 | df = self.setup_dataframe(df.copy()) |
| 1274 | |
| 1275 | df['trend'] = self.predict_trend(df) |
| 1276 | seasonal_components = self.predict_seasonal_components(df) |
| 1277 | if self.uncertainty_samples: |
| 1278 | intervals = self.predict_uncertainty(df, vectorized) |
| 1279 | else: |
| 1280 | intervals = None |
| 1281 | |
| 1282 | # Drop columns except ds, cap, floor, and trend |
| 1283 | cols = ['ds', 'trend'] |
| 1284 | if 'cap' in df: |
| 1285 | cols.append('cap') |
| 1286 | if self.logistic_floor: |
| 1287 | cols.append('floor') |
| 1288 | # Add in forecast components |
| 1289 | df2 = pd.concat((df[cols], intervals, seasonal_components), axis=1) |
| 1290 | df2['yhat'] = ( |
| 1291 | df2['trend'] * (1 + df2['multiplicative_terms']) |
| 1292 | + df2['additive_terms'] |
| 1293 | ) |
| 1294 | return df2 |
| 1295 | |
| 1296 | @staticmethod |
| 1297 | def piecewise_linear(t, deltas, k, m, changepoint_ts): |