A Streamlit application for analyzing customer acquisition attribution using XGBoost and SHAP values.
This application analyzes the Criteo Uplift dataset to predict customer conversion probabilities and explain feature attributions using SHAP (SHapley Additive exPlanations) values.
- Interactive feature input through sliders
- Real-time conversion probability prediction
- Feature attribution analysis with SHAP values
- Global feature importance visualization
- Clone this repository
- Install dependencies:
pip install -r requirements.txt - Run the app:
streamlit run streamlit_app.py
- Push this repository to GitHub
- Log in to Streamlit Cloud
- Create a new app and connect it to your GitHub repository
- Set the main file path to
streamlit_app.py - Deploy!
- The app will first try to load the dataset from the local
datadirectory - If not found, it will try to load from a local compressed file
- As a last resort, it will download the dataset from Criteo's URL
- If all data loading methods fail, a small synthetic dataset will be used as a fallback
This app uses the Criteo Uplift dataset. The dataset will be automatically downloaded if not present locally.
See requirements.txt for a list of dependencies.
Businesses invest heavily in marketing campaigns, website features, and user experience improvements, but struggle to isolate the true causal impact of these interventions on conversion rates or other key metrics. Standard correlation-based attribution models often misattribute conversions, leading to inefficient resource allocation. It's challenging to determine if a user converted because of a specific touchpoint (true uplift) or if they would have converted anyway. ImpactIQ tackles this by employing causal inference techniques to measure the incremental impact (uplift) of specific treatments (e.g., ad exposure, feature usage) on individual user behavior, specifically focusing on purchase decisions within complex user journeys.
ImpactIQ leverages uplift modeling, a branch of causal inference, to estimate the difference in the probability of an outcome (e.g., purchase) when a user is exposed to a treatment versus when they are not.
- Data Preparation: Utilizes datasets with explicit treatment/control group assignments (like the Criteo Uplift Prediction dataset) or observational data where pseudo-experiments can be constructed. Requires careful preprocessing to handle features, treatment flags (
treatment), and outcome flags (visit,conversion). - Uplift Modeling: Implements advanced uplift models using libraries like EconML. Techniques may include:
- Meta-Learners: Such as the Two-Model approach (T-Learner - separate models for treatment/control groups), S-Learner (single model with treatment as a feature), or X-Learner (more robust for heterogeneous treatment effects).
- Tree-based Methods: Causal Forests or Uplift Trees that directly optimize for uplift.
- Instrumental Variable / Double Machine Learning (DML): EconML's DML estimators are particularly powerful for observational data, using nuisance models (for outcome and treatment propensity) to isolate the causal effect. XGBoost is often used for these high-capacity nuisance models.
- Feature Engineering: Creates interaction features and relevant user characteristics to capture potential heterogeneous treatment effects (i.e., how uplift varies across different user segments).
- Evaluation: Assesses model performance using uplift-specific metrics like the Qini curve, Area Under the Uplift Curve (AUUC), and cumulative uplift charts, rather than traditional classification metrics (Accuracy, AUC).
- Simulation & Deployment: Provides a Streamlit-based simulator for exploring "what-if" scenarios and demonstrating model predictions. The architecture is designed conceptually for near real-time application using a Kafka stream for data ingestion and a model serving component.
- Dataset: Primarily developed using the Criteo Uplift Prediction Dataset. This dataset contains user features, a binary treatment indicator, and binary outcome indicators (visit and conversion), making it ideal for uplift modeling benchmarking.
- Modeling Core: EconML's
CausalForestDMLor other DML estimators (LinearDML,NonParamDML) are often employed, leveragingXGBoostorLightGBMas the underlying machine learning models for estimating the conditional outcome E[Y|X, W] and treatment propensity E[T|X, W]. This approach helps control for confounding variables (W) when estimating the effect of treatment (T) on outcome (Y) given features (X). - Evaluation Metrics:
- Qini Curve / AUUC: Measures the cumulative uplift gained by targeting users in descending order of predicted uplift score. A higher curve indicates better model performance.
- Uplift@k: The average uplift observed in the top k% of users ranked by predicted uplift.
[User Interaction Data Stream (e.g., Website Clicks, Ad Views)] ->[Kafka Topic: Raw Events] ->[Python Processing Service (Consumer)] ->[Feature Engineering & Preprocessing] ->[EconML/XGBoost Uplift Model (Inference)] ->[Output: Uplift Scores per User/Interaction] ->[Streamlit Dashboard / API Endpoint (Results & Simulation)][Database/Data Store (Logging Scores)]* Ingestion: Kafka handles high-volume event streams.
- Processing: Python service consumes events, performs feature lookups/generation, and applies the trained uplift model.
- Serving/Visualization: Model predictions are served via an API or visualized directly in a Streamlit application for analysis and simulation. Got it! Below is the content rewritten in a Notion-friendly Markdown format, using clean formatting, indentation, and spacing that aligns with how Notion renders markdown (headings, bold, inline math, code blocks, and bullet points). It's ready to copy and paste into a Notion page or markdown file.
ImpactIQ is an uplift modeling engine designed to quantify the incremental impact of a treatment (e.g. marketing campaign, promotion) by comparing outcomes between a treatment group and a control group.
Unlike traditional machine learning models that predict likelihood of an outcome, uplift models estimate the causal effect of an intervention on an individual or segment level.
In uplift tree-based models, each decision tree uses both:
treatment_column: indicates whether an observation received the treatmentresponse_column: indicates whether an observation responded (e.g. converted, clicked)
This allows a single tree to model both treatment and control groups jointly, instead of building separate trees per group.
The algorithm searches for splits that maximize the divergence in outcomes between treatment and control subgroups, rather than optimizing metrics like Gini impurity or squared error.
The splitting criteria in uplift trees rely on a configurable uplift_metric, which measures how different the treatment and control distributions are after a potential split.
An asymmetric divergence measure that tends toward infinity when probabilities include zeros.
- Used in information theory
- Sensitive to zero probabilities
A symmetric and stable distance metric that does not diverge to infinity.
- Numerically stable
- Common in clustering and distance-based models
An asymmetric measure normalized by the control group distribution.
- Useful for evaluating statistical independence
- May also diverge when control group has zeros
Where:
P: treatment group distributionQ: control group distribution
Each split's value in a node is computed as:
The final split gain is normalized using:
- Gini impurity for
euclideanorchi_squared - Entropy for
KL
Each leaf in an uplift tree contains two conditional probabilities:
TP_l: treatment prediction (likelihood of response if treated)CP_l: control prediction (likelihood of response if not treated)
Computed as:
Where:
l: current leafT_l: number of treatment group samples in leafC_l: number of control group samples in leafTY1_l: treatment group responses (treatment = 1, response = 1)CY1_l: control group responses (treatment = 0, response = 1)
The uplift score for a leaf is:
A positive uplift score indicates the treatment likely caused a higher response rate.
A negative score means the control group had a higher response rate, implying the treatment may have had a negative impact.
As in standard decision forest models, the final prediction is the average uplift score across all trees in the ensemble.
When calling the predict() method on test data, the output includes:
uplift_predict: uplift score (i.e. difference between predicted probabilities)p_y1_with_treatment: probability of response if treatedp_y1_without_treatment: probability of response if not treated

