Politecnico di Milano
APPLIED STATISTICS PROJECT

Who should an online shop spend its marketing on?

Online Shoppers' Purchasing Intention — a decision-first analysis.
Applied Statistics · June 2026.
A crowd of faceless figures, a few highlighted in blue and teal
The problem

Most visitors never buy — so we can't chase everyone.

  • 12,330 shopping sessions; only 15.5% end in a purchase (1,908 sessions).
  • The marketing budget is limited.
  • Goal: find the few likely buyers, skip the rest.
15.5% buy
1,908 of 12,330 sessions
Online Shoppers' Purchasing Intention dataset · 12,330 sessions
02
Approach

Every analysis ends in a decision, not a chart.

Decision-first: each step must change a real action.

Four questions, in the order we'll answer them:

RQ-A
Segments
who are the visitors?
RQ-B
Drivers
what makes them buy?
RQ-D
Engine
can we predict it?
RQ-C
Cost decision
who do we target?
Our decision-first approach
03
The data

A rare "yes" — and four codes that look like numbers.

  • One row = one visit; the target is Revenue (bought? yes/no).
  • 12,330 sessions × 18 fields, 0 missing, 10 months (no January/April).
  • OperatingSystems, Browser, Region, TrafficType look numeric but are codes → treated as categories.
  • 125 duplicate rows kept on purpose. Source: UCI #468 (Sakar et al., 2018).
Bar chart: Revenue False 84.5% versus True 15.5%
15.5% Revenue = True — the rare "yes"
UCI #468 · Sakar et al., 2018
04
What the data already shows

One signal already separates buyers from the rest.

  • PageValues is a Google Analytics metric: the average value of the pages a visitor saw, weighted toward those that usually lead to a purchase.
  • When PageValues = 0, only ~4% buy (9,600 sessions); when > 0, ~56% buy (2,730).
  • It's the jump from absent → present, not a specific cut-off.
  • Season matters: November ~25% vs February ~2%. New visitors (~25%) beat returning ones (~14%).
Conversion rate rises sharply from PageValues 0 to above 0, then grows gradually
~4% → ~56% buy
the 0 → >0 jump
Conversion rate by PageValues band
05
How we kept it honest

We never let the model peek, and we judged it on the buyers.

Raw data
12,330 sessions
Split 80 / 20
seed 42 · before any fitting
Test · 2,466
locked away until the end
train · 9,864
Nested cross-validation
SMOTE only inside the folds
Judge on buyers
PR-AUC · ROC-AUC · F1
≠ accuracy85% = useless
  • Split 80/20 before any fitting (train 9,864 / test 2,466; seed 42); scaling and preprocessing are learned on train only.
  • Nested cross-validation; rebalancing (SMOTE) only inside the folds.
  • Success = PR-AUC + ROC-AUC + F1 on buyers, not accuracy (a "nobody buys" model is ~85% accurate but useless).
  • Tools: Python, scikit-learn, statsmodels — fully reproducible.
Evaluation protocol
06
Key design choices

Three choices we made on purpose.

01
Two feature sets
9 behavioural signals to segment; all features to predict.
02
PageValues kept out of the clustering
a page-level metric, not this session's label — not leakage, just so close to the outcome it would dominate and distort the groups.
03
The decision threshold comes from costs
not from a default 0.5.
Modeling decisions
07
RQ-A Segments

Visitors come in three clear types.

Bounce
~7% of sessions, buy ~1% (in and out).
Browsing
~74%, buy ~15% (the big middle).
High-intent
~19%, buy ~24% (already interested).
Conversion by segment: Bounce 1.1%, Browsing 14.8%, High-intent 23.9%
K-means segments · conversion by segment
08
RQ-A How we found them

Two different methods, the same three groups.

UMAP scatter colored by segment, three separated clusters at k=3
  • Silhouette (how cleanly groups separate) ~0.43; k=2 is higher (~0.55) but gives only two groups — too coarse to act on.
  • Hierarchical clustering agrees (ARI ~0.90) — the three groups aren't an artefact of one method: two different methods agree.
k = 3 PCA (3 components ≈ 87% variance) → K-means.
UMAP colored by segment (k=3)
09
RQ-A Robustness

A completely different lens finds the same groups.

  • Build a similarity network (k-NN, k=15) and let communities form on their own (Louvain).
  • The 14 communities it finds are clean: modularity ~0.80, purity ~0.97 — each sits inside one segment.
  • Simplify the network → ~4 macro-communities: one Bounce, one High-intent, two Browsing — so no new type appears.
Two UMAP panels: network communities (Louvain) and the same sessions colored by k-means segment, occupying the same regions
Caveat: same 9 variables → this is an internal cross-check, not independent proof.
k-NN network · Louvain communities vs k-means segments
10
RQ-B Drivers

PageValues is the strongest signal of buying; high exit rates the strongest behavioural signal against it.

Logistic regression (pseudo-R² ~0.42), read as odds ratios — how much each factor multiplies the odds of buying (above 1 = more likely, below 1 = less likely):

  • PageValues ~4.2 (strong pull), ExitRates ~0.45 (brake), returning visitor ~0.61, November ~1.75.
  • Trustworthy because collinearity was fixed first (ExitRates VIF 8.7 → 2.2, after dropping its twin BounceRates).
  • A Random Forest cross-check (permutation importance, in the appendix) confirms the same ranking — so PageValues' strength isn't just an effect of it having many distinct values.
Forest plot of conversion drivers as odds ratios with 95% CI; reference line at 1.0
1.0 = no effect
Conversion drivers · odds ratio (95% CI), log scale
11
RQ-B Heterogeneity
Our original contribution

The same driver doesn't pull equally for everyone.

  • The overall PageValues pull (OR ~4.2, Slide 11) splits by segment: stronger in Browsing (~4.6) than in High-intent (~2.6) — so we push Browsing and only lightly touch the already-warm High-intent (Slide 16).
  • The segment × PageValues interaction is strong (p < 0.001).
  • Month × visitor-type interaction is real (p ≈ 0.001); weekend × traffic is not (p ≈ 0.9).
Odds ratio by segment: PageValues pull is 4.6 in Browsing versus 2.6 in High-intent; reference line at 1.0
Odds ratio by segment · significant difference only for PageValues
12
RQ-D The engine

Random Forest wins — on calibration, not on the score.

  • Nested CV over 8 model families (CV means): RF PR-AUC 0.748 vs GradientBoosting 0.741 — a tie, the gap isn't meaningful.
  • Tiebreak · Brier in CVcalibration (how well predicted probabilities match the real buy-rate): lower Brier in cross-validation, 0.069 vs 0.070.
  • On the unseen test: PR-AUC 0.73 (95% CI 0.69–0.77), ROC-AUC 0.92.
Model comparison PR-AUC: RandomForest 0.748 and GradientBoosting 0.741 nearly tied, ahead of six other models
Model comparison · PR-AUC (nested CV, mean ± sd)
13
RQ-D The honest caveat

Take PageValues away and the score halves — we don't hide it.

With PageValues
0.73
Without it
0.36
PR-AUC, test

With PageValues: PR-AUC 0.73 (ROC 0.92). Without it: PR-AUC 0.36 (ROC 0.77).

RandomForest with vs without PageValues on test: PR-AUC 0.73 to 0.36, ROC 0.92 to 0.77, base rate 0.15
  • PageValues-included (0.73) = post-visit targeting — the model behind our recommendation; PageValues-excluded (0.36) = the conservative real-time floor.
  • PageValues builds up during a visit, so a live model sits between the two. Even 0.36 beats the 15% base rate.
"PAGEVALUES ISN'T ZERO MID-SESSION"

True — it accumulates, so 0.36 (fully removed) is a lower bound and 0.73 (full) an upper bound; the real-time value lies between.

RandomForest · with vs without PageValues (test)
14
RQ-C The decision threshold

Missing a buyer hurts more — so we move the line.

  • Set costs 5:1 (a lost buyer ≈ 5 wasted offers) → threshold t* = 1/(1+5) ≈ 0.17, not 0.5.
  • Recall jumps 0.55 → 0.85; precision ~0.51.
  • The threshold comes from the costs, not from fitting the data.
Expected economic loss vs threshold; minimized near t* from costs = 0.167, far below the default 0.5
t* ≈ 0.17
Expected economic loss vs threshold · cost ratio 5:1
15
RQ-C Who exactly to target

Push Browsing, touch High-intent lightly, skip Bounce.

BrowsingPrimary
recall 0.84 (within-segment), precision 0.56 — the budget goes here.
High-intentLight touch
recall 0.89 (within-segment), precision 0.43 — just make buying easier.
BounceSkip
only 4 buyers in the test, ~1% conversion → not worth it.
Net: the 0.85 overall recall comes almost entirely from these two segments — targeting Browsing + High-intent alone captures ~84% of all buyers.
Targeting impact by segment: total buyers vs buyers captured for Bounce, Browsing, High-intent at t*=0.167
Targeting impact by segment · test, t*=0.167
16
RQ-C Robust to the cost assumption

The recommendation holds even if we got the costs wrong.

Vary the cost ratio r:

r
Recall
Precision
2
0.71
0.62
5Base
0.85
0.51
10
0.90
0.43
The targeted segments stay the same — only how hard we push them changes. Transparent and robust.
Decision sensitivity to cost ratio: recall rises and precision falls from r=2 to r=10, base scenario r=5
Decision sensitivity to the cost of losing a customer
17
The recommendation

From 12,330 sessions to one clear spending decision.

The four questions form one story (see table): segments → drivers → engine → cost-aware decision.

Research question
Question
Method
Key result
Metric
A · Segmentation
Who are the visitors?
PCA, K-means, UMAP
3 types: Bounce / Browsing / High-intent
silhouette 0.43; ARI vs Revenue 0.01 (by design — not the label)
Graphs · Validation
Are the segments real?
k-NN network + Louvain (Graph theory)
Pure communities within the segments (sub-types)
modularity 0.80; purity 0.97
B · Drivers
What drives buying? Does it change across segments?
Logistic + RF importance
PageValues/ExitRates dominant; heterogeneous drivers
pseudo-R² 0.42
D · Engine
Which predictive model?
Nested CV over 8 models
RandomForest (chosen for calibration)
PR-AUC 0.73 (CI 0.69–0.77); without PV 0.36; ROC-AUC 0.92
C · Prioritization
Where to target?
Threshold via expected economic loss
Target Browsing; ~84% buyers (2 segments)
t*=0.17; recall 0.85; F1 (buyers) 0.64
The answer: target the Browsing segment (lightly High-intent), catching ~84% of buyers under a cost-based rule.
Results by research question · summary
18
Limitations & future work

What we'd flag before trusting this in production.

Limits
  • Genuine real-time power is ~0.36 (PageValues is a near-target signal, fully known only by the end of a visit).
  • Test = random split over the same 10 months — so 0.73 is in-distribution, not an out-of-time check (Jan/Apr untested).
  • The graph check isn't independent (same features); heterogeneity rests mainly on one driver.
  • F1 on buyers ~0.64 (cost-based threshold) — just below the 0.65–0.72 target.
  • Bounce is fragile (4 buyers); 5:1 cost ratio is an assumption.
  • Drivers are associations, not causes.
Future work
  • A/B-test the drivers
  • Add real-time features
  • Validate out-of-time (hold out a future month)
  • Test more cost scenarios
Limitations · what to validate next
19
Scattered points converging through an arrow into a single focused target
Politecnico di Milano
In closing

The best model is the one that makes a better decision.

Thank you questions welcome.
20
A
Backup material

Appendix

Kept at the end and not presented — jumped to only if a question calls for it.
Politecnico di Milano
APPENDIXRebalancing comparison

How did SMOTE / class weights compare?

Plain GB has the lowest economic loss and the best Brier in cross-validation (training folds) — rebalancing did not help here.

GB pure vs GB+sample_weight vs GB+SMOTE: economic loss and Brier
Appendix · not presented
A1
APPENDIXCalibration

Are the probabilities reliable? Why RF?

Both models hug the diagonal (test Brier ≈ 0.071–0.072); RF was chosen on cross-validation calibration.

Reliability diagram: RandomForest and GradientBoosting both close to perfect calibration
Appendix · not presented
A2
APPENDIXConfusion matrix · test

Show the real errors.

PR-AUC 0.729 on test. At the provisional 0.5 threshold: 209 buyers caught, 173 missed, 75 false alarms.

Precision-recall curve PR-AUC 0.729 and confusion matrix at 0.5: 2009/75/173/209
Appendix · not presented
A3
APPENDIXPermutation + PDP

Is PageValues importance a cardinality artefact?

Model-agnostic permutation keeps PageValues far ahead — not a cardinality artefact; PDP rises then plateaus.

Permutation importance ranks PageValues first; partial dependence of PageValues rises then plateaus
Appendix · not presented
A4
APPENDIXCollinearity · VIF

How did you handle collinearity?

Dropping BounceRates pulls ExitRates from VIF 8.7 to ~2.2 (green = acceptable).

VIF naive vs resolved specification; ExitRates drops below 5 after dropping BounceRates
Appendix · not presented
A5
APPENDIXMonth × visitor interaction

Show the interaction you found.

New visitors out-convert returning in most months, but the gap shifts month to month (interaction p ≈ 0.001).

Conversion by month for new vs returning visitors, lines crossing in places
Appendix · not presented
A6
APPENDIXDendrogram

How does hierarchical clustering compare?

Ward linkage; cutting at the red line gives three main branches — consistent with k = 3.

Ward dendrogram with a cut line yielding three main branches
Appendix · not presented
A7
APPENDIXRF importance

What does the forest say drives it?

Gini importance ranks PageValues and pagevalues_gt0 first, then ExitRates — matching the logistic story.

Random Forest Gini feature importance, PageValues highest
Appendix · not presented
A8
APPENDIXMetrics glossary

The metrics in one line each.

PR-AUC
Area under the precision–recall curve — ranking quality on the rare buyers.
ROC-AUC
Chance a random buyer is ranked above a random non-buyer.
F1
Harmonic mean of precision and recall (here, on buyers).
Precision / Recall
Of those flagged, how many buy / of all buyers, how many we catch.
Odds ratio
How much a factor multiplies the odds of buying (>1 up, <1 down).
VIF
Variance inflation — how much a predictor is explained by the others.
Silhouette
How cleanly the clusters separate (−1 to 1; higher is better).
ARI
Adjusted Rand Index — chance-corrected agreement between two partitions (two clusterings, or a clustering vs the true labels).
Modularity
How much denser links are inside communities than expected by chance.
Purity
Share of a community that falls in its dominant segment.
Brier
Mean squared error of predicted probabilities (lower = better calibrated).
Nested CV
Cross-validation with an inner loop to tune, an outer loop to score honestly.
SMOTE
Synthetic minority oversampling — adds synthetic buyers, inside CV folds only.
Expected economic loss
Total cost of errors given the cost ratio, summed over decisions.
Threshold t*
The probability cut-off that minimises expected loss (here ≈ 0.17).
Appendix · not presented
A9
APPENDIXChoosing k

Why k = 3 (not 2 or 4)?

Silhouette alone is higher at k=2 (~0.55) than k=3 (~0.43), but k=2 merges two behaviourally distinct, decision-relevant groups — Browsing and High-intent — into one. We keep k=3 because it yields the three actionable profiles the whole cost decision relies on, and because a graph cross-check — same 9 variables, so an internal check, not independent proof — recovers the same three groups, each network community sitting inside one segment (purity ~0.97, modularity ~0.80).

Elbow and silhouette plots for K-means with the chosen k=3 marked
Answers — "Why three segments and not two or four?"
A10
APPENDIXLiterature comparison

How our results compare to the literature.

Aspect
Published work on this dataset
This project
Headline metric
Accuracy, typically 88–95% (misleading at a 15.5% positive rate)
PR-AUC 0.73, always paired with the no-PageValues floor 0.36
ROC-AUC
typically 0.85–0.99
0.92
PR-AUC
almost never reported; the one study that did ≈ 0.75
0.73
PageValues role
universally the #1 feature, but rarely quantified
same — and we quantify its removal (0.73 → 0.36)
With / without PageValues
independent replications: F1 ≈ 0.68 → 0.37
PR-AUC 0.73 → 0.36; logistic pseudo-R² 0.42 → 0.14
Imbalance handling
SMOTE is the common choice
class-weighted model, test left imbalanced
We use the metric the imbalance demands, pair it with an honest floor, and measure the feature everyone else only names.

External figures from a literature scan — Sakar et al. 2019, CMU Stat Capstone 2022, a 2023 gradient-boosting study, among others.

Answers — "Is 0.73 any good? Is this already known?"
A11
APPENDIXInterpretive ablation

Drivers without PageValues (interpretive ablation).

Re-fitting the interpretive (logistic) driver model without PageValues drops McFadden pseudo-R² from 0.42 to 0.14 — the same collapse the predictive engine shows (PR-AUC 0.73 → 0.36), seen from the regression side. PageValues dominates the explanation, not just the prediction.

Logistic odds ratios with and without PageValues; pseudo-R-squared falls from 0.42 to 0.14
Answers — "Does the driver story also collapse without PageValues?"
A12
APPENDIXPCA variance

PCA variance retained.

Three principal components retain ~87% of the variance in the behavioural features — the basis for the k-means segmentation.

Scree plot and cumulative variance; three components reach about 87%
Answers — "Why 3 components / ~87% of the variance?"
A13