Case 01 / Customer analytics · Forecasting
Who may stop buying, and what might they spend?
A time-based customer analytics system built on historical retail transactions. It compares models for future purchase inactivity and individual revenue, describes customer segments, then brings those signals together in a capacity-aware retention review.
- LSTM
- GRU
- Logistic Regression
- Random Forest
- XGBoost
- Tweedie GLM
- BG/NBD
- Gamma-Gamma
- K-Means
- PyTorch
- Streamlit
- 01 / HISTORYBuild time-based snapshotsCustomer activity available at each forecast cutoff
- 02 / INACTIVITYModel weekly behaviorLSTM sequence scores alongside tabular and statistical benchmarks
- 03 / VALUEForecast customer revenueExpected 90-day gross revenue, with model comparisons and bias checks
- 04 / REVIEWJoin the evidenceRisk, value, and descriptive segments in an adjustable review queue
- September customer cohort
- 5,224identified customers at the final forecast cutoff
- LSTM precision at top 10%
- 90.6%September retrospective inactivity comparison
- 90-day revenue MAE
- £362.57per customer · September retrospective comparison
Turn purchase history into a customer-level decision.
The project asks two related questions at a forecast date: who is likely to make no purchase in the next 90 days, and how much gross merchandise revenue might each customer generate in that period? These are evaluated against future transactions, not assigned from lifetime totals or random customer splits.
A separate behavioral segmentation provides context for review. The Streamlit app joins the three outputs by customer and cutoff so users can filter and rank a limited set of customers for investigation.
Respect what was known at each cutoff.
UCI Online Retail II supplies historical transactions. After transaction filtering, the project builds 24,866 customer-cutoff rows over six quarterly cutoffs from June 2010 through September 2011. The final September cohort has 5,224 identified customers with qualifying history.
Each snapshot uses past purchase behavior only. Inactivity is the absence of a qualifying purchase in the following 90 days; revenue is gross merchandise value from that customer's qualifying future purchases in the same horizon. The sequence branch represents history in 26 weekly bins. Both targets are tied to a date, so model selection and calibration must wait until their outcome windows are observable.
Test whether the weekly sequence adds value.
The lead inactivity model is a weekly LSTM because the project explicitly studies temporal purchase dynamics. Logistic regression, Random Forest, XGBoost, a purchase-hazard model, MLP, and GRU remain in the benchmark. Feature-based competitors use purchase recency, frequency, spending, product variety, and related history summaries.
On the retrospective September comparison, the LSTM reached 90.6% precision among the 10% highest-risk customers and 0.819 average precision. It was chosen for the sequence-learning question, not because it won every metric: recency-only logistic regression had the best March development top-decile precision at 89.4%, versus 88.7% for the LSTM. The model comparison remains visible in the app and repository.
Forecast expected value and inspect the misses.
Customer-level revenue is sparse and uneven, so the project compares recent-spend baselines, regression and hurdle models, XGBoost, probabilistic sequence modeling, and transaction-based BG/NBD with Gamma-Gamma spending. The expanded 90-day selection uses a mean-oriented Tweedie criterion across eligible development origins.
The selected enriched monthly XGBoost model had £362.57 September customer-level MAE, compared with £373.47 for the original XGBoost reference. Aggregate revenue underforecast improved from 42.7% to 25.5%, but remains material. The six-month BG/NBD/Gamma-Gamma experiment has a June forecast origin and is kept separate from the September 90-day retention review.
Make the signals explorable together.
Two descriptive customer groups are fitted from June 2011 behavior using PCA and K-Means, then assigned to the September cohort. A five-component Gaussian Mixture is preserved as an alternative. The segments describe historical behavior; they do not define the future targets or prove different treatment effects.
The review joins September LSTM inactivity risk, expected 90-day gross revenue, and segment for all 5,224 customers. Users can filter customers, change review capacity, and compare ranking rules. The default 10% setting creates a 523-customer queue ranked by inactivity risk multiplied by historical average order value. That score is a prioritization heuristic, not an estimate of recoverable revenue or campaign lift.
A retrospective decision aid, not a live campaign result.
The source data ends in December 2011. The September evaluations are retrospective historical comparisons, and the data contains no outreach assignment or campaign response. Scores therefore cannot establish that contacting a customer would change purchases. Gross revenue also excludes margin and intervention cost.
The revenue model still underforecasts in aggregate, and the six-month and 90-day forecasts have different origins. The repository retains the competing models, documented metrics, reproducible pipeline, and local Streamlit review app.