ML-driven revenue prediction, explainability (SHAP + LIME), and real-time campaign optimization for digital advertising.
Quick Start β’ Features β’ Architecture β’ API Reference β’ Model Performance
AdPulse is a full-stack campaign intelligence system that combines machine learning, explainable AI, and real-time analytics to help marketing teams predict revenue, understand model decisions, and optimize ad spend across channels.
AdPulse goes beyond simple predictions β it provides actionable insights backed by SHAP/LIME explanations, budget optimization, and AI-powered campaign analysis.
| Traditional Analytics | AdPulse |
|---|---|
| Backward-looking reports | Predictive revenue forecasting |
| Black-box models | SHAP + LIME explainability |
| Manual budget allocation | ROAS-weighted auto-optimization |
| Static dashboards | Real-time interactive intelligence |
| No risk detection | ML-powered anomaly alerts |
- Revenue Prediction Engine β XGBoost + LightGBM ensemble with RΒ² = 0.993 accuracy
- Spend Sensitivity Analysis β Revenue impact curves across Β±50% spend scenarios
- Campaign Health Scoring β Composite metric combining intent, quality, and efficiency
- Risk Detection β Automatic flagging of underperforming campaigns
- SHAP Global Explanations β Top revenue drivers ranked by impact magnitude
- SHAP Dependence Plots β Visualize how individual features influence predictions
- LIME Local Explanations β Instance-level model explanations for any campaign
- Business Insight Narratives β Auto-generated human-readable recommendations
- Campaign Chat Analyst β GPT-4o-mini / HuggingFace / rule-based fallback
- Ad Copy Analyzer β Sentiment analysis + engagement prediction via HuggingFace NLP
- Creative Analyzer β Image quality scoring via Google Cloud Vision API
- Budget Optimizer β ROAS-weighted allocation across channels
- 10+ interactive pages β Overview, Campaigns, Predict, Explainability, AI Tools, Budget, Segments, Reports, Alerts
- Dark/Light theme β Toggle between sleek dark mode and clean light mode
- Responsive design β Works on desktop and mobile
- Real-time data β Live connection to FastAPI backend
- Conversion funnel β Visual funnel from impressions β clicks β conversions β revenue
AdPulse/
βββ backend/
β βββ main.py # FastAPI server (610 lines, 15+ endpoints)
β βββ .env.example # API key template
β βββ AdPulse-DataSprint/ # Backend sub-module
β
βββ frontend/
β βββ dashboard.html # Single-page dashboard (1447 lines)
β
βββ notebook/
β βββ DataSprint_WinningNotebook.ipynb # Original Jupyter notebook
β βββ datasprint_complete_notebook.py # Python script version
β
βββ artifacts/ # Pre-trained ML models & data
β βββ best_xgb.joblib # Tuned XGBoost model
β βββ best_lgb.joblib # Tuned LightGBM model
β βββ shap_explainer.joblib # SHAP TreeExplainer
β βββ lime_config.joblib # LIME configuration
β βββ feature_columns.joblib # Feature column list
β βββ model_metrics.joblib # Evaluation metrics
β βββ shap_data.joblib # Pre-computed SHAP values
β βββ cluster_model.joblib # KMeans campaign clusters
β βββ model_meta.json # Model metadata
β βββ df_clean_full_with_features.csv # Processed dataset
β
βββ digital_media_dataset.csv # Raw dataset (3000+ campaigns)
βββ requirements.txt # Python dependencies
βββ LICENSE # MIT License
βββ README.md # This file
graph LR
A[π CSV Upload] --> B[FastAPI Backend]
B --> C[Data Cleaning & Feature Engineering]
C --> D[XGBoost + LightGBM Ensemble]
D --> E[Revenue Prediction]
D --> F[SHAP Explainer]
D --> G[LIME Explainer]
E --> H[Dashboard UI]
F --> H
G --> H
B --> I[AI Chat - GPT-4o / HuggingFace]
B --> J[Ad Copy Analyzer - NLP]
B --> K[Creative Analyzer - Vision API]
B --> L[Budget Optimizer]
I --> H
J --> H
K --> H
L --> H
- Python 3.9+
- pip (Python package manager)
git clone https://github.com/YOUR_USERNAME/AdPulse.git
cd AdPulse# Create virtual environment (recommended)
python -m venv .venv
# Activate it
# Windows:
.venv\Scripts\activate
# macOS/Linux:
source .venv/bin/activate
# Install packages
pip install -r requirements.txt# Copy the example env file
cp backend/.env.example backend/.env
# Edit with your keys (optional β the app works without them)
# - OPENAI_API_KEY β for GPT-4o-mini chat
# - HF_TOKEN β for HuggingFace NLP models
# - GOOGLE_APPLICATION_CREDENTIALS β for Vision APINote: AdPulse works fully without API keys. AI features gracefully fall back to rule-based responses.
cd backend
uvicorn main:app --reload --port 8000Navigate to http://localhost:8000 in your browser.
Go to the Upload Data page and upload digital_media_dataset.csv to load campaign data.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/health |
Server health check + model status |
POST |
/api/upload |
Upload campaign CSV for processing |
GET |
/api/campaigns |
Retrieve all campaigns with metrics |
GET |
/api/campaigns/summary |
Aggregated KPI summary |
POST |
/api/predict |
Predict revenue for given parameters |
GET |
/api/shap/global |
SHAP global feature importance |
POST |
/api/chat |
AI campaign analyst (multi-provider) |
POST |
/api/analyze-copy |
NLP ad copy sentiment analysis |
POST |
/api/analyze-creative |
Image quality scoring (Vision API) |
POST |
/api/optimize-budget |
ROAS-weighted budget allocation |
GET |
/api/report/csv |
Download campaign report as CSV |
GET |
/api/report/company |
Generate JSON executive report |
GET |
/api/model/info |
Model metadata and metrics |
| Model | RΒ² Score | RMSE | MAE | MAPE |
|---|---|---|---|---|
| XGBoost | 0.9852 | $1,893 | $941 | 11.34% |
| LightGBM | 0.9977 | $749 | $378 | 4.53% |
| Ensemble (55/45) | 0.9933 | $1,272 | $618 | 6.02% |
- Optimizer: Optuna TPE Sampler
- XGBoost: 80 trials
- LightGBM: 60 trials
- Cross-validation: 5-fold stratified
| Rank | Feature | Avg |SHAP| | Direction |
|---|---|---|---|
| 1 | spend_efficiency |
0.412 | β Revenue |
| 2 | conversions |
0.338 | β Revenue |
| 3 | clicks |
0.291 | β Revenue |
| 4 | funnel_velocity |
0.254 | β Revenue |
| 5 | conversion_rate_pct |
0.219 | β Revenue |
| Layer | Technology |
|---|---|
| Backend | FastAPI, Uvicorn, Python 3.9+ |
| ML Models | XGBoost, LightGBM, scikit-learn |
| Explainability | SHAP (TreeExplainer), LIME (TabularExplainer) |
| Clustering | KMeans (k=4), StandardScaler |
| Tuning | Optuna (TPE Sampler) |
| AI Chat | OpenAI GPT-4o-mini, HuggingFace Mistral-7B |
| NLP | HuggingFace (RoBERTa Sentiment, BART-MNLI) |
| Vision | Google Cloud Vision API |
| Frontend | Vanilla HTML/CSS/JS, Canvas API |
| Data | Pandas, NumPy |
cd backend
uvicorn main:app --reload --port 8000 --log-level infoTo retrain models from scratch, run the notebook:
cd notebook
python datasprint_complete_notebook.pyThis will regenerate all artifacts in the artifacts/ directory.
FastAPI provides automatic interactive API docs:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
The project uses a digital media advertising dataset with 3,000+ campaigns across:
- 6 Channels: Search, Social Media, Display, Email, Video, Affiliate
- 4 Regions: North America, Europe, Asia-Pacific, Latin America
- 3 Device Types: Mobile, Desktop, Tablet
- 40+ Features after engineering (log transforms, ratios, interaction terms)
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License β see the LICENSE file for details.
Khushee Dengale
GitHub
Built with β€οΈ and a lot of β
