CoolFace
Apppublic

GulShair/marketing-mix-modeling-app

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

Marketing Mix Modeling Dashboard

An interactive Streamlit app for exploring how advertising spend across TV, Radio, and Newspaper relates to Sales. It uses a polynomial regression model trained on the classic advertising dataset to predict sales, analyze ROI, simulate scenarios, optimize budget allocation, and surface data-driven insights.

What it does

The app has seven pages, selectable from the sidebar:

  • Dashboard — headline metrics, channel/sales correlations, spend share, a correlation heatmap, sales distribution, and a 3D predicted-sales surface.
  • Sales Predictor — enter a spend mix and get predicted sales, a data-grounded Low/Medium/High category, and an estimated error range based on the model's test RMSE.
  • ROI Analyzer — converts predicted sales to revenue and computes profit and ROI%, with a gauge chart, interpretation bands, and CSV export.
  • What-If Simulator — apply percentage changes to a baseline mix and compare baseline vs scenario sales (and revenue) side by side.
  • Budget Optimizer — finds the channel split that maximizes predicted sales for a given total budget, bounded to the model's trustworthy range.
  • Insights — automated findings computed from the data and model (correlations, Newspaper's weak signal, TV diminishing returns, contribution breakdown, reallocation upside) plus per-channel diminishing-returns charts. Exportable to CSV.
  • Upload Dataset — upload your own CSV, validate it, preview it, and optionally retrain the model with a side-by-side metric comparison before applying.

How to run

Requires Python 3.9+.

bash
pip install -r requirements.txt
streamlit run app.py

The app opens in your browser (default http://localhost:8501).

To retrain the bundled model from the command line:

bash
python model/train_model.py

Folder structure

MarketingMixApp/
├── app.py                  # Streamlit app: all pages, layout, styling
├── requirements.txt        # Python dependencies
├── README.md
├── .streamlit/
│   └── config.toml         # Dark theme configuration
├── data/
│   └── advertising.csv     # Training dataset (TV, Radio, Newspaper, Sales)
├── model/
│   ├── train_model.py      # Training pipeline + reusable retrain functions
│   ├── predictor.py        # Loads the saved model and predicts sales
│   └── saved_model.pkl     # Persisted model, transformer, and metrics
└── utils/
    ├── roi.py              # ROI calculation logic
    ├── optimizer.py        # Budget allocation optimizer (scipy SLSQP)
    └── insights.py         # Data/model-driven insight generation

Model and its limitations

The model is a degree-2 polynomial regression (PolynomialFeatures + LinearRegression) trained with an 80/20 train/test split.

Please read these caveats before trusting any number:

  • Small dataset. The advertising dataset has only ~200 rows. Estimates are directional, not precise, and the model can be sensitive to the specific train/test split.
  • Newspaper has weak signal. Newspaper spend correlates only ~0.16 with Sales in this data — essentially no meaningful predictive relationship. The app flags this explicitly and the optimizer caps Newspaper allocation so it isn't over-weighted on numerical noise.
  • Extrapolation is unreliable. The model is only trustworthy within the range of spend it was trained on. Inputs outside that range trigger a warning, and the optimizer is bounded near each channel's observed maximum.
  • Predictions are estimates, not guarantees. Real sales depend on many factors outside this dataset (seasonality, competition, pricing, etc.). Retraining on new data is not guaranteed to improve the model — always compare metrics before applying a retrained model.