Build Recency, Frequency and Monetary Features From Order History
Last updated: November 29, 2026
Quick Overview
Given a table of customer orders, compute recency, frequency and average order value features as of a snapshot date for a purchase propensity model, making sure no order on or after the snapshot is used.
Amazon
November 29, 20260
0
0 solved
Given a table of customer orders, compute recency, frequency and average order value features as of a snapshot date for a purchase propensity model, making sure no order on or after the snapshot is used.
RFM features are a staple of Amazon retail marketing and propensity models. The question checks that a candidate can write clean aggregation code and respects the snapshot boundary that keeps features honest.
What the Interviewer Expects
- Filters orders strictly before the snapshot date
- Computes recency in days from the most recent prior order
- Computes counts and average value per customer
- Handles customers with no prior orders
- Mentions windowed versions and log transforms for skew
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- How would you add 30, 90 and 365 day windows efficiently?
- What would you return for a customer with no orders before the snapshot?
- How would you do this in SQL for 300 million customers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
Confirm the schema (customer_id, order_date, amount), whether returns or cancellations should be excluded, and what the snapshot date is....
Approach
One pass over orders: skip any order with date on or after the snapshot, track the latest date, a count and a running sum per customer, then derive recency in days and average spend. Customers with no...