# deejayrusso/marketing-mix-model architecture

> Architecture diagram of the GitHub repository deejayrusso/marketing-mix-model, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/deejayrusso/marketing-mix-model
- Repository: https://github.com/deejayrusso/marketing-mix-model

## Overview

##### Project type and purpose
- This is a data‐science/analytics pipeline—a marketing mix modeling project—rather than a multi‐tier web application.
- Purpose: generate simulated weekly media‐spend & sales data, engineer features, train multiple regression models (OLS, polynomial, Lasso, Ridge, Elastic Net, SGD) to predict sales from TV and paid‐search spend, and surface the best model.

##### File structure
- Top level:
– Data Generation – AMSS.R → R script invoking the AMSS package to simulate time‐series marketing & sales data
– ObservedData.csv → the resulting simulated data
– Marketing Mix Model – final.ipynb → Jupyter notebook containing data loading, EDA, feature engineering, model training, evaluation, and interpretation
– Marketing Mix Model Presentation.pdf → export of findings and visualizations
– README.md → project overview, methodology, and future directions
- No separate “src” or “lib” folders, so the notebook itself orchestrates data ingestion, transformation, modeling, and visualization.

##### README for additional insights
- External dependencies:
– R AMSS package for data simulation
– Python data stack (pandas, numpy, scikit-learn, matplotlib/seaborn) in the notebook
- Workflow steps are enumerated (1 through 10), outlining the pipeline from data generation through model comparison and interpretation.

##### Main components and interactions (to include
a. Data Generation Component
– “Data Generation – AMSS.R” calls AMSS, outputs ObservedData.csv
b. Raw Data Storage
– ObservedData.csv sits in a staging area
c. Data Ingestion & Exploration Module
– Notebook cell group “Generate data and load simulated data” and “Explore data”
d. Feature Engineering Module
– Notebook cells creating lag variables & rolling averages
e. Data Pipeline / Preprocessing
– Split into train/test, apply Yeo-Johnson transforms, label encoding if any
f. Model Training & Evaluation Module
– Six model blocks (OLS, polynomial, Lasso, Ridge, Elastic Net, SGD)
– Calculation of RMSE, MAPE for train/test
g. Model Selection & Interpretation
– Compare metrics, select Lasso, interpret coefficients
h. Output & Reporting
– Notebook visualizations, “Marketing Mix Model Presentation.pdf”

##### Relationships and data flow
1. R script → CSV
2. CSV → Notebook Ingestion
3. Ingestion → EDA → Feature Engineering → Preprocessing → Model Training → Evaluation → Selection
4. Final results → PDF report / visualizations
- Feedback loops if re-running the simulation or tuning hyperparameters

##### Architectural patterns and design principles
- Pipeline pattern: linear ETL (Extract → Transform → Load) feeding into model training
- Modularity: each notebook section acts as a module; maintain clear separation
- Reproducibility: record exact AMSS version, Python environment, random seeds

##### Key technologies, frameworks, and libraries
- R & AMSS package (data simulation)
- Python (Jupyter, pandas, numpy, scikit-learn, scipy, matplotlib/seaborn)
- GitHub for version control, README for documentation

##### Essential architectural elements in detail
- Call out the transformation stage (Yeo-Johnson) as it materially affects interpretability.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Sources
    DataGen["Data Generation (AMSS.R)"]:::process
    RawData["ObservedData.csv"]:::dataSource
    Doc["README.md"]:::doc

    %% Processing Modules
    Ingest["Data Ingestion & Exploration"]:::process
    FeatureEng["Feature Engineering"]:::process
    Preprocess["Data Pipeline / Preprocessing"]:::process

    %% Model Training & Evaluation
    subgraph "Model Training & Evaluation" 
        direction TB
        OLS["OLS Regression"]:::model
        Poly["Polynomial Regression"]:::model
        Lasso["Lasso Regression"]:::model
        Ridge["Ridge Regression"]:::model
        ElasticNet["Elastic Net"]:::model
        SGD["SGD Regression"]:::model
    end

    Selection["Model Selection & Interpretation"]:::process
    Output["Marketing Mix Model Presentation.pdf"]:::output

    %% Data Flow
    DataGen -->|"1. simulate data"| RawData
    RawData -->|"2. load data"| Ingest
    Ingest -->|"3. feature engineering"| FeatureEng
    FeatureEng -->|"4. preprocessing"| Preprocess
    Preprocess -->|"5. train models"| OLS
    Preprocess --> Poly
    Preprocess --> Lasso
    Preprocess --> Ridge
    Preprocess --> ElasticNet
    Preprocess --> SGD
    OLS -->|"evaluate"| Selection
    Poly --> Selection
    Lasso --> Selection
    Ridge --> Selection
    ElasticNet --> Selection
    SGD --> Selection
    Selection -->|"6. report"| Output

    %% Documentation link
    Doc -.-> DataGen
    Doc -.-> Ingest
    Doc -.-> Selection

    %% Click Events
    click DataGen "https://github.com/deejayrusso/marketing-mix-model/blob/main/Data Generation - AMSS.R"
    click RawData "https://github.com/deejayrusso/marketing-mix-model/blob/main/ObservedData.csv"
    click Ingest "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model - final.ipynb"
    click FeatureEng "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model - final.ipynb"
    click Preprocess "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model - final.ipynb"
    click OLS "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model - final.ipynb"
    click Poly "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model - final.ipynb"
    click Lasso "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model - final.ipynb"
    click Ridge "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model - final.ipynb"
    click ElasticNet "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model - final.ipynb"
    click SGD "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model - final.ipynb"
    click Selection "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model - final.ipynb"
    click Output "https://github.com/deejayrusso/marketing-mix-model/blob/main/Marketing Mix Model Presentation.pdf"
    click Doc "https://github.com/deejayrusso/marketing-mix-model/blob/main/README.md"

    %% Styles
    classDef dataSource fill:#cce5ff,stroke:#004085,color:#004085;
    classDef process fill:#d4edda,stroke:#155724,color:#155724;
    classDef model fill:#ffe5b4,stroke:#ff8c00,color:#ff8c00;
    classDef output fill:#f5c6cb,stroke:#721c24,color:#721c24;
    classDef doc fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
