Case study · Machine learning, team of two

Starbucks Offer Targeting

Starbucks sends Rewards members BOGO and discount offers, but many people would have bought anyway and others never look. With a teammate, I built a pipeline that predicts who will actually respond, groups customers into segments, and uses uplift modelling to spend a fixed offer budget where it changes behaviour.

2.4×more extra responses than random targeting, same budget
0.78ROC-AUC on a time-based held-out test set
81%of real responders caught (recall)
4customer segments from K-Means
01Question

An offer only pays off if it changes what the customer does. Sending a discount to someone who would have bought anyway costs margin, and sending one to someone who never opens the app is wasted. So there are three questions: who responds, what kinds of customer exist, and given a fixed reward budget, who should get an offer?

02Approach
ParseRaw JSON → parquetOffers, profiles, event transcript
LabelLeakage-safe targetReceived → viewed → completed, inside the offer window
Features3 familiesDemographics, pre-offer behaviour, offer design
ModelTuned classifiersTime-based train / validation / test split
SegmentK-Meansk picked by elbow + silhouette
SpendUplift + budgetRank by extra response per reward dollar

Only count real responses

A positive label means the customer viewed the offer and then completed it before it expired. Completing without viewing stays negative, because the offer didn't cause the purchase.

No peeking at the future

Behavioural features use only events before each offer arrived, and the train/test split follows time order, so test scores reflect real forecasting.

03My part

Data exploration & plotting

Wrote the first exploration notebook and the shared plotting utilities used throughout the project.

7-day spend velocity features

Added "spend in the last 7 days" and "transactions in the last 7 days" before each offer, using point-in-time merge_asof joins so no future data leaks in.

Hyperparameter tuning

Added RandomizedSearchCV (15 draws, 3-fold CV, optimising F1) with search spaces for logistic regression, random forest and XGBoost.

Decision thresholds

Replaced the fixed 0.5 cutoff with the threshold that maximises F1 on validation data (0.32 for XGBoost), then re-ran every evaluation and explanation report.

# customer_features.py: spend velocity just before each offer (time is in hours)
features["time_7d_ago"] = features["received_time"] - 168
history_7d = pd.merge_asof(..., left_on="time_7d_ago", right_on="time", by="person", direction="backward")
features["spend_last_7d"] = features["total_spend_before"] - features["spend_7d_ago"]

Niloy led the raw-data parsing, target construction, feature pipeline, clustering, uplift model, budget simulation and test suite.

04Findings

What the models found

All figures are from the repo's reports, on held-out data.

Held-out test: ROC-AUC

Time-based split: 30,420 train rows, 20,412 test rows.

XGBoost0.783
Random forest0.782
Logistic reg.0.746
Baseline0.500

XGBoost: F1 0.62, precision 0.51, recall 0.81. The majority-class and rule-based baselines score F1 0.

Budget simulation: extra responses

Same budget (25% of total reward value) spent two ways.

Uplift-ranked124
Random51

Expected incremental responses from 12,209 candidates. Uplift picked 3,119 offers. Random is the mean of repeated draws (± 1.4).

Offer completion rate by segment

K-Means, k = 4 (best silhouette, 0.255). Segment names are descriptive.

Big spenders (101)52.5%
Older, affluent (5,122)49.5%
Loyal regulars (4,687)43.3%
New, light buyers (7,018)14.6%

The largest group joined most recently (about 315 days), averages $5 per visit, and almost never completes offers.

Strongest XGBoost signals

Feature importance (gain share).

Gender not given0.36
Sent via social0.11
Age missing0.09
Income missing0.08
BOGO offer0.08

Bars scaled to the top feature. Confirmed with a SHAP summary in the repo.

Incomplete profiles are the biggest tell

Whether a customer filled in their gender, age and income mattered more than any spending feature. Members who skip their profile behave very differently with offers.

Channel matters

Offers sent through social media were the second-strongest signal, ahead of reward size or difficulty.

Target by incremental effect, not by likelihood

Ranking by uplift per reward dollar got 2.4× the extra responses that random targeting got for the same spend.