Building a Time-Safe Retention Prediction Model
Machine LearningModel answerLast updated
Design a feature set and validation strategy to predict whether users will remain active, avoiding temporal leakage and quantifying predictive lift.
You are working with two datasets: a user table containing registration timestamp and subscription tier, and an events table with timestamped user actions. Your task is to build a model that predicts whether users will remain active in the future.
You are considering several candidate features:
- Count of events per user
- Number of distinct days with activity
- Subscription tier at registration
- Day of week when the user signed up
Describe your approach to building and validating this model. Your answer should address:
- How you define the prediction problem (what time point are you predicting from, what does "retained" mean, what is the outcome window)
- How you construct features that respect temporal boundaries and avoid leakage
- How you validate that your features provide genuine predictive signal beyond simple baselines
- What evaluation methodology you would use and why
Be explicit about any assumptions you make regarding the retention definition and time windows.
Hints
Hint 1
Define a clear cutoff: features use data before time T, the label uses data after T
Hint 2
Compare your model against a simple baseline like 'predict the overall retention rate for everyone'
Hint 3
Consider what happens when a user has zero events in the feature window
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
1. Problem Definition and Timeline
I'll define the prediction task with explicit temporal boundaries:
- Observation window: Days 0–7 after signup (the first week)
- Prediction point: End of day 7
- Outcome window: Days 8–37 (the following 30 days)
- Retention label: User is "retained" if they have at least one event during the outcome window
This creates a clean separation: all features are computed using only data from days 0–7, and the label is determined by activity in days 8–37. This prevents temporal leakage where future information influences the prediction.
Why this definition? Early-week behavior is often predictive and actionable for intervention. A 30-day outcome window balances signal strength (longer windows capture more true churn) with business relevance (shorter feedback loops enable faster iteration).
2. Feature Construction
For each user, I construct features using only their first 7 days:
Behavioral features:
event_count_week1: Total events in days 0–7active_days_week1: Number of distinct days with ≥1 event in days 0–7avg_events_per_active_day:event_count_week1 / max(active_days_week1, 1)to avoid division by zero
Signup features:
plan_type: Categorical (e.g., free, premium)signup_dow: Day of week encoded as 0–6 or asis_weekendbinary
Handling missing data: Users with zero events in week 1 get event_count_week1 = 0 and active_days_week1 = 0. They are included in the dataset (predicting retention for inactive users is a valid and important use case), not filtered out.
Leakage check: No feature uses data after day 7. Event timestamps are always before the prediction point.
3. Baseline and Model Validation
Baseline model: Predict the population retention rate for all users. If 60% of users are retained, the baseline always predicts 0.6 probability. This is often called the "naive" or "marginal" baseline.
Model: Start with logistic regression on the features above. Logistic regression provides interpretable coefficients and probability calibration, making it a strong choice before moving to more complex models.
Evaluation metrics:
- AUC-ROC: Measures discriminative ability (can the model rank users by retention likelihood?)
- Log loss / Brier score: Measures calibration (are predicted probabilities accurate?)
- Precision-Recall curve: Useful if retention is imbalanced (e.g., 80% retained, 20% churned)
Validation strategy: Use time-based cross-validation (not random splits). For example:
- Cohort 1 (weeks 1–4): train on weeks 1–3, validate on week 4
- Cohort 2 (weeks 2–5): train on weeks 2–4, validate on week 5
- Report average performance across folds
Random splitting would leak information because users from the same time period appear in both train and test, ignoring drift over time.
4. Feature Importance and Ablation
To determine which features add signal:
Coefficient analysis (for logistic regression): Examine feature coefficients and their confidence intervals. A coefficient significantly different from zero suggests the feature matters.
Ablation study: Train the model with and without each feature, measuring the drop in validation AUC:
- Full model AUC: 0.72
- Without
active_days_week1: 0.68 (Δ = 0.04, significant) - Without
plan_type: 0.71 (Δ = 0.01, less impactful)
Permutation importance: Shuffle each feature in the validation set and measure performance degradation. Features with large drops are more important.
5. Addressing Common Pitfalls
Class imbalance: If 85% of users are retained, a model predicting "retained" for everyone achieves 85% accuracy but is useless. Use AUC, precision-recall, or reweight the loss function to balance classes.
Overfitting to early adopters: Early cohorts may differ from later users (early adopters are more engaged). Validate on recent cohorts held out entirely from training.
Calibration: A model with AUC = 0.75 might still produce poorly calibrated probabilities (e.g., predicting 0.9 when true rate is 0.6). Use calibration plots and recalibrate with isotonic regression or Platt scaling if needed.
Simpson's paradox across plans: plan_type might confound other features. Stratify analysis by plan to check if event_count has the same effect within each tier.
6. Communicating Uncertainty
State clearly:
- "This model achieves AUC = 0.72 on held-out recent cohorts, compared to 0.50 for the baseline."
- "Active days in week 1 is the strongest predictor (ablation Δ AUC = 0.04)."
- "Predictions are calibrated to ±5% in the 0.4–0.8 probability range but underestimate retention for very low-activity users."
Avoid claims like "this feature causes retention" (correlation ≠ causation) or "this model will work forever" (drift is real).
Summary
A strong retention model separates training and outcome periods cleanly, constructs features without leakage, evaluates against a meaningful baseline using time-aware validation, and quantifies which features drive lift. The approach balances statistical rigor with practical interpretability.