Baselining ‐ Prophet decomposition - yadijustforfun/SP-transition GitHub Wiki

Prophet Decomposition: Overview

Prophet (developed by Facebook/Meta) is a forecasting tool designed for time series data with trends, seasonality, and holidays. Its decomposition feature breaks down a time series into interpretable components:

  1. Trend (long-term growth/decline).
  2. Seasonality (weekly, yearly, or custom patterns).
  3. Holiday Effects (impact of special events).
  4. Residuals (noise not explained by the model).

When to Use Prophet Decomposition

  1. Interpretability

    • You need to understand how trends, seasonality, and holidays affect your data (e.g., retail sales, web traffic).
    • Example: Decomposing daily Uber rides to see weekly peaks (weekends) and yearly trends.
  2. Forecasting with Regular Patterns

    • Works best when data has strong, predictable seasonality (e.g., electricity demand, airline passengers).
  3. Handling Missing Data & Outliers

    • Robust to gaps and abrupt changes (unlike traditional ARIMA).
  4. Quick Prototyping

    • Requires minimal configuration compared to SARIMA or deep learning (LSTMs).
  5. Including External Regressors

    • Can add holiday calendars or custom events (e.g., Black Friday sales).

When NOT to Use Prophet Decomposition

  1. High-Frequency Data (e.g., seconds/minutes)

    • Designed for daily/weekly/monthly data. Use Fourier transforms or LSTMs for sub-daily patterns.
  2. Irregular or Complex Seasonality

    • Fails if seasonality changes abruptly (e.g., crypto prices). STL or TBATS may work better.
  3. Non-Additive Trends

    • Assumes additive seasonality by default (use multiplicative=True for multiplicative trends).
  4. Large-Scale Multivariate Forecasting

    • Prophet is univariate. For multivariate dependencies, use VAR or neural networks.
  5. Very Short Time Series

    • Needs at least 1-2 seasonal cycles (e.g., 2 years of monthly data).

Example: Prophet Decomposition in Python

from fbprophet import Prophet
import pandas as pd

# Sample data (Yahoo Finance-style CSV)
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv')

# Fit model
model = Prophet(seasonality_mode='additive')
model.fit(df)

# Decompose
future = model.make_future_dataframe(periods=365)
forecast = model.predict(future)

# Plot components
fig = model.plot_components(forecast)

Output Plots:

  1. Trend (overall growth).
  2. Weekly Seasonality (e.g., higher usage on weekends).
  3. Yearly Seasonality (if data spans multiple years).

Prophet Decomposition


Alternatives to Prophet

Use Case Better Tool
High-frequency data Fourier Methods, LSTMs
Complex seasonality STL, TBATS
Multivariate forecasting VAR, Neural Nets
Sparse data Gaussian Processes

Key Takeaways

  • Use Prophet for interpretable, seasonal, univariate forecasts with holidays.
  • Avoid Prophet for high-frequency, multivariate, or irregularly changing patterns.
  • Always validate with out-of-sample tests (e.g., cross_validation in Prophet).

Controlling Factors in Prophet

How Controlling Factors Are Captured

  • Explicit Regressors: Prophet allows direct inclusion of known control variables (e.g., marketing spend, temperature) via add_regressor().
  • Holidays/Events: Modeled as binary indicators (e.g., 1 on Black Friday).
  • Linear or Nonlinear Effects: By default, regressors have linear effects, but custom adjustments can capture nonlinear relationships.

Why This Works

  • Interpretability: Each regressor’s contribution is quantified with clear coefficients.
  • Uncertainty Estimation: Provides posterior intervals for regressor impacts (if using MCMC).
  • Flexibility: Handles missing data and supports dynamic regressors (time-varying effects).

Can You Read Out Contributions?

  • Yes, explicitly:
    • plot_components(): Visualizes marginal effects of each regressor.
    • Forecast DataFrame: Columns like regressor_effect show the contribution over time.
  • Example:
    model.plot_components(forecast)  # Shows holiday + regressor impacts
    

When to Use Prophet

  • Known controls (e.g., promotions, weather).
  • Interpretable forecasts (need to explain driver contributions).
  • Univariate time series with external factors.

Limitations

  • Univariate only: No native support for multivariate dependencies.
  • Linear assumptions: Nonlinear effects require manual feature engineering.

Key Takeaway

Prophet excels when you need transparent, quantifiable control factors (e.g., "Marketing spend increased sales by 10% ± 2%"). Use it for business-friendly explanations over latent methods like ALS.