Bayesian Modeling · Sports Analytics

FanPulse — Bayesian Marketing Mix Model for MLB Fan Demand

Overview

FanPulse is a Bayesian Marketing Mix Model (MMM) that decomposes MLB game attendance across multiple demand drivers — competitive factors, weather, promotions, and marketing spend — using 11,972 real home games from five seasons (2019, 2021–2024). The goal is to quantify what actually moves the needle on attendance and enable interactive budget-planning scenarios.

What was built

  • Full Bayesian MMM in PyMC with geometric adstock transforms (carry-over effects) and Hill saturation curves (diminishing returns) for each marketing channel.
  • Hierarchical model with partial pooling across all 30 MLB teams — shares signal between teams while preserving team-specific effects.
  • Reset-aware adstock: boundary conditions prevent data leakage between team-seasons (end of one season doesn't carry into the next).
  • Time-based holdout validation on the 2024 season — trained on 2019–2023 data, validated out-of-sample. R² ≈ 0.33, MAPE ≈ 23.9% (holdout).
  • Budget optimization via SciPy SLSQP constrained solver — finds the spend allocation across channels that maximizes predicted attendance given a total budget.
  • Six-page interactive Streamlit dashboard: EDA, model results, diagnostics, scenario planner, and methodology — backed by ArviZ posterior summaries.
  • Clear data provenance: real attendance and game results from Baseball Reference; synthetic marketing spend data clearly labeled as illustrative.
  • Modular codebase: backend/models/, backend/utils/, streamlit_app/pages/ with separate concerns across ingestion, modeling, and UI.

Why it matters

Traditional marketing attribution uses last-touch or linear rules that ignore carry-over effects and diminishing returns — both of which are central to how advertising actually works. Bayesian MMM quantifies uncertainty in every coefficient rather than producing point estimates, making the budget recommendations more honest. The holdout R² of 0.33 reflects genuine out-of-sample difficulty (attendance is noisy) rather than overfit train-set numbers.

Project Info

  • Category: Bayesian Modeling / Sports Analytics
  • Data: 11,972 MLB home games — 2019, 2021–2024
  • Holdout: R² ≈ 0.33, MAPE ≈ 23.9% (2024 season)
  • Stack: PyMC, PyTensor, ArviZ, SciPy, pybaseball, Streamlit, pandas
  • GitHub: fanpulse