Add markers for significant changepoints to prophet forecast plot. Example: fig = m.plot(forecast) add_changepoints_to_plot(fig.gca(), m, forecast) Parameters ---------- ax: axis on which to overlay changepoint markers. m: Prophet model. fcst: Forecast output from m
(
ax, m, fcst, threshold=0.01, cp_color='r', cp_linestyle='--', trend=True,
)
| 442 | |
| 443 | |
| 444 | def add_changepoints_to_plot( |
| 445 | ax, m, fcst, threshold=0.01, cp_color='r', cp_linestyle='--', trend=True, |
| 446 | ): |
| 447 | """Add markers for significant changepoints to prophet forecast plot. |
| 448 | |
| 449 | Example: |
| 450 | fig = m.plot(forecast) |
| 451 | add_changepoints_to_plot(fig.gca(), m, forecast) |
| 452 | |
| 453 | Parameters |
| 454 | ---------- |
| 455 | ax: axis on which to overlay changepoint markers. |
| 456 | m: Prophet model. |
| 457 | fcst: Forecast output from m.predict. |
| 458 | threshold: Threshold on trend change magnitude for significance. |
| 459 | cp_color: Color of changepoint markers. |
| 460 | cp_linestyle: Linestyle for changepoint markers. |
| 461 | trend: If True, will also overlay the trend. |
| 462 | |
| 463 | Returns |
| 464 | ------- |
| 465 | a list of matplotlib artists |
| 466 | """ |
| 467 | artists = [] |
| 468 | if trend: |
| 469 | artists.append(ax.plot(fcst['ds'], fcst['trend'], c=cp_color)) |
| 470 | signif_changepoints = m.changepoints[ |
| 471 | np.abs(np.nanmean(m.params['delta'], axis=0)) >= threshold |
| 472 | ] if len(m.changepoints) > 0 else [] |
| 473 | for cp in signif_changepoints: |
| 474 | artists.append(ax.axvline(x=cp, c=cp_color, ls=cp_linestyle)) |
| 475 | return artists |
| 476 | |
| 477 | |
| 478 | def plot_cross_validation_metric( |
nothing calls this directly
no test coverage detected
searching dependent graphs…