Model Evaluation and Validation Questions
Measuring whether a model is good enough to trust and ship. Covers metric selection for classification, regression, and ranking (precision/recall, ROC-AUC, calibration, RMSE), offline validation design, evaluation-metric-to-business-objective alignment, and production safety guardrails. Emphasizes choosing metrics that reflect real objectives and avoiding misleading evaluations.
Your offline evaluation shows Model A clearly beating Model B, but the online A/B test shows no meaningful difference. Propose an investigation plan to identify the cause, and recommend concrete changes to your offline evaluation process to improve alignment going forward.
Sample Answer
Investigation plan: goal: find why offline lift (A > B) didn't surface online. I'll run targeted checks in parallel (triage → hypothesis testing → remediation).
- Reproduce the discrepancy
- Verify offline evaluation uses the exact same model artifacts, preprocessing, feature generation, and decision logic as deployed.
- Run a small shadow test in production (log model A and B decisions on live traffic without affecting users) to compare predictions and inputs.
- Metric alignment
- Compare offline objective vs online KPI. Map model output → business action → online metric. If offline uses log-loss or AUC but online cares about click-through or conversion, retrain/evaluate using the online metric (or a proxy such as calibrated probabilities leading to same decision thresholds).
- Compute calibration and decision-threshold swept offline performance for the exact online metric.
- Sampling bias / population shift
- Compare train/validation distribution to online traffic (user segments, time-of-day, geos, devices). Use population statistics (feature marginals), covariate shift tests (KL, PSI), and model performance broken down by segment.
- If bias found, reweight offline test set to match production distribution or evaluate on stratified holdouts.
- Instrumentation and logging
- Audit feature generation and any upstream transformations in production for missing/lagged features, default fill values, or unit mismatches. Check feature freshness and latency.
- Validate online event instrumentation for the outcome label (deduplication, attribution windows, causal assignment correctness).
- Feature leakage and training-serving skew
- Scan for features that leak future info in offline pipeline (timestamps, labels-derived features). Run a “time-forward” evaluation where features only use information available at decision time.
- Compare feature statistics between training snapshots and serving logs to catch serving-time approximations.
- Exposure and feedback loops
- Check whether model A changes downstream user behavior differently (novelty, long-term effects) not captured offline. Run short-term vs long-term metric analysis and look for delayed signals.
- Ensure randomization in A/B test is correct and no spillover between buckets.
Applying this to the stated scenario: suppose Model A scored 0.85 AUC offline versus Model B's 0.80, a 5-point offline gap, but online conversion came back at 3.20% for A versus 3.19% for B, statistically indistinguishable. Step 2 (metric alignment) would check whether that 5-point offline AUC gap actually maps to more relevant top-ranked items in the live product, since AUC rewards correct ranking across the whole score range while conversion only cares about the handful of items actually surfaced to a user; a model can win on AUC by getting the middle of the distribution right while tying on the top-k that users actually see. Step 3 (sampling bias) would check whether the offline evaluation set's traffic mix (say, weighted toward desktop, daytime, US users) matches the live population the A/B test actually ran on; if Model A's 5-point AUC edge came disproportionately from segments underrepresented in live traffic, the offline number overstates what online users would ever notice. Working through even one of these two steps against the actual scenario numbers, rather than leaving them as generic checklist items, is usually enough to locate which of the two explanations (metric mismatch or population mismatch) is driving the specific gap.
Concrete changes to offline evaluation
- Use holdout sets that mimic production sampling (stratified by geo/device/time) and apply importance weighting when distributions differ.
- Evaluate using the online business metric (or a well-validated proxy); perform threshold-based and counterfactual simulations to map offline scores to online decisions.
- Implement production shadowing as standard: daily sample of live traffic scored with both models and logged for retrospective analysis.
- Add automatic checks: calibration, PSI per feature, training-serving skew alerts, and unit tests validating feature parity.
- Remove or flag any features that rely on future signals; enforce “information cutoff” during dataset assembly.
- Periodically run randomized offline experiments (simulate assignment logic) and maintain an issues playbook linking offline failure modes to remediation steps.
Expected outcome: faster root-cause identification, higher offline/online correlation, fewer failed launches.
Design a comprehensive evaluation framework for a large-scale search or recommendation product serving tens of millions of users monthly. Cover offline metrics (NDCG@k, recall@k, MAP), how you would correct for position and exposure bias, the online metrics you would track (CTR, revenue, retention), the logging schema needed for counterfactual evaluation, and how offline evaluation, online A/B tests, and champion-challenger deployment fit together.
Sample Answer
Requirements & goals:
- Evaluate ranking quality (relevance), business outcomes (CTR, revenue, retention), and long-term user satisfaction at 100M DAU with low risk.
Offline metrics & protocol:
- Relevance: NDCG@k (Normalized Discounted Cumulative Gain: rewards a ranked list for placing relevant items near the top, discounts relevant items that appear further down, and normalizes against the best possible ordering so scores are comparable across queries), Recall@k (of all the relevant items that exist, the fraction that showed up anywhere in the top k), MAP@k (Mean Average Precision: the average precision computed at each rank position where a relevant item appears in the top k, then averaged across queries) computed on holdout sessions; use session-level aggregation and per-user temporal splits (train on t, test on t+delta).
- Calibration & confidence: compute confidence intervals via bootstrapping by user.
- Diversity & novelty: catalog-based measures (intra-list diversity, coverage).
Correcting position/exposure bias:
- Propensity scoring via logged exposure probabilities (from serving logs): use IPS (inverse propensity scoring) and SNIPS (Self-Normalized IPS: the same reweighting idea as IPS, but rescaled by the sum of the propensity weights rather than by the raw sample count, which reduces the wild variance plain IPS can have when some items had very low exposure probability) to unbiasedly estimate CTR and NDCG.
- Train position-bias models (e.g., an examination model / PBM) to estimate propensities when they aren't logged directly.
- Use doubly robust estimators combining IPS with outcome models to reduce variance.
Online metrics:
- Immediate: raw CTR, conversion rate, revenue per thousand impressions.
- Short-term engagement: session length, day-over-day retention.
- Long-term value: 7/30/90-day retention, LTV, churn rate, downstream purchases.
Logging schema (must be complete & immutable):
- Event id, user_id (hashed), timestamp, session_id, request_id, placement_id, rank_list (item_ids + positions), served_probabilities (model score, softmax prob), exposure_flag per item, click/engagement events with timestamps, item metadata (owner, category), context (device, region), policy_version, experiment_id, traffic_bucket, reward signals (purchase, watch_time), prior user-state feature snapshot. Ensure deterministic replay keys and a sampling indicator for subsampling.
Counterfactual eval & offline simulator:
- Offline simulator: replay logged requests, simulate alternative policies using logged propensity or importance weights. Include synthetic user-response models learned from logs for stress tests (e.g., adversarial content).
- Use IPS/SNIPS/doubly robust for policy evaluation. Validate simulators by backtesting on historical A/B tests.
A/B testing & system components:
- Experiment platform: traffic allocation, randomization (user-level), exposure logging, kill switch.
- Metrics pipeline: near-real-time aggregator for guardrail metrics, weekly cohort analyses for long-term metrics.
- Policy rollout: staged (canary to ramp), automatic risk checks (statistical significance and business bounds).
- Analysis tools: automated uplift estimation, sequential testing with alpha-spending (a rule for how much of your total false-positive budget you're allowed to spend by peeking at a running experiment's results early, so repeated interim looks don't silently inflate the overall false-positive rate the way naive repeated significance testing would), and variance reduction via stratification/ANCOVA (Analysis of Covariance: adjusting an experiment's outcome metric for a pre-experiment covariate, like each user's prior engagement level, to strip out predictable noise before comparing groups, which tightens confidence intervals without needing more traffic).
How offline evaluation, online A/B tests, and champion-challenger deployment fit together:
- Offline metrics are the fast, cheap FILTER: any new policy must beat the current champion on the offline holdout and the offline simulator (using IPS/SNIPS/DR) before it is allowed anywhere near real traffic. This is the stage that screens out most bad candidates for near-zero cost.
- A/B testing is the causal VALIDATION step: a policy that clears the offline bar gets a randomized, low-traffic online test against the current champion, because even debiased offline estimators can miss position-bias or feedback-loop effects that only appear with real exposure.
- Champion-challenger is the ONGOING PRODUCTION pattern once a challenger has won its A/B test: instead of a full one-shot replacement, the challenger is promoted to serve a small, sustained slice of live traffic (e.g. 5-10%) permanently alongside the incumbent champion, with the same online metrics tracked continuously rather than for a fixed test window. This catches slow drift, seasonality, and small regressions a short A/B window would miss, and gives an instant, no-redeploy rollback (shift traffic back to the champion) if the challenger degrades later. Only after a sustained period of the challenger matching or beating the champion does it get promoted to be the new champion, at which point a fresh challenger can be tested against it.
- Together the three form a funnel of increasing cost and decreasing risk: offline (cheap, many candidates screened, imperfect signal) -> A/B (moderate cost, causal, time-boxed) -> champion-challenger (small ongoing cost, the steady-state safety net that a time-boxed test can't provide).
Long-term impact tracking:
- Cohort-based LTV and retention dashboards, causal impact analyses (difference-in-differences, synthetic controls), monitor content-provider effects and feedback loops (popularity bias).
- Periodic offline retraining with debiased labels and causal features to prevent feedback loops.
Trade-offs & operational notes:
- Logging volume: sample some heavy fields but keep deterministic keys for replay.
- Bias-variance: IPS is unbiased but high variance; prefer doubly robust estimators in production.
- Privacy: hash/anonymize PII; consider differential privacy for aggregate dashboards.
This framework provides unbiased offline evaluation, safe online experimentation, and a champion-challenger steady state to iterate recommendation policies at scale with continuous, low-cost safety monitoring.
Explain uplift (heterogeneous treatment effect) modeling and the metrics used to evaluate it, such as the Qini coefficient and uplift@k. Describe a business use case, for example a marketing campaign, where uplift modeling is clearly preferable to simply predicting conversion probability directly, and how you would run an experiment to validate that targeting by uplift actually increases ROI.
Sample Answer
Uplift (treatment-effect) modeling predicts the causal incremental effect of applying a treatment (e.g. a marketing action) on an individual's outcome versus not treating them. Unlike standard outcome prediction P(y|x), uplift estimates tau(x) = E[Y|X=x, T=1] - E[Y|X=x, T=0]. Common model families: two-model (separate models for treated/control), S-/T-/X-learners, and causal forests or meta-learners that directly target treatment heterogeneity.
Evaluation metrics:
- Uplift curve: plot cumulative incremental response when targeting top-ranked individuals by predicted tau(x). X-axis = proportion targeted; Y-axis = cumulative incremental gains.
- Qini curve & Qini coefficient: the uplift analogue of the ROC/AUC; the Qini curve plots incremental responders vs targeted population; the Qini coefficient is the area between the Qini curve and the random-targeting baseline, higher is better.
- uplift@k (area under the uplift curve, AUUC): incremental gain when treating the top k% (practical for budgeted campaigns).
- These metrics require randomized treatment assignment (or careful causal adjustment) to get an unbiased ground-truth increment; use cross-validation across trials and confidence intervals via bootstrap.
Why prefer uplift over outcome prediction:
Scenario: promotional marketing with a cost to contact. A response model predicts who will buy, but many high-propensity buyers would purchase anyway, so contacting them wastes budget. Uplift modeling identifies persuadable customers (positive tau) and avoids 'do-not-disturb' customers (negative tau, who are harmed by contact). Business impact: higher ROI, lower cost-per-incremental-conversion, and a better customer experience for people who would have converted regardless.
Validating that targeting by uplift actually increases ROI
The naive design (compare a contacted, uplift-targeted group against an untreated control) measures the value of the TREATMENT, not the value of the TARGETING STRATEGY, and will look good even if the uplift model is no better than random targeting, because contacting anyone at all usually beats contacting no one. To isolate the targeting strategy's value, run a three-arm randomized experiment instead:
- Arm 1 (uplift-targeted): contact the top-k% of customers ranked by predicted tau(x).
- Arm 2 (random-targeted, same budget): contact a random k% of customers, holding contact volume and cost identical to Arm 1.
- Arm 3 (no-contact holdout): a small held-out slice used only to estimate the untreated baseline conversion rate needed to validate the tau(x) estimates themselves, not for the ROI comparison.
The ROI comparison that actually answers the question is Arm 1 vs Arm 2: since both arms incur the same contact cost, any difference in conversion or revenue between them isolates the value of picking the right k% via uplift, from the value of contacting people at all. Compute incremental profit per contacted customer for each arm as (conversion_rate * avg_order_value) - cost_per_contact, and test the difference between arms with a two-sample test or bootstrap CI, sized via a power analysis using the historical variance in per-customer revenue. Pre-register the primary metric (incremental profit per contact, Arm 1 minus Arm 2) before launch, and require both statistical significance and a minimum practical ROI delta (covering rollout and maintenance cost) before rolling the uplift model out to full targeting.
Key practical notes:
- Need randomized or well-controlled observational data plus propensity adjustment if the historical treatment assignment was not randomized.
- Common pitfalls: selection bias in who was historically treated, and lack of overlap (some segments never treated historically, so tau(x) is unidentified there without extrapolation).
Explain Goodhart's Law and how metric gaming happens when a team optimizes a proxy metric instead of the true business objective (for example optimizing for clicks and getting clickbait). Give concrete examples, and propose an evaluation regime to detect and mitigate it: adversarial holdout sets, randomized audits, tracking long-term business metrics, and continuous monitoring for improvements that don't correlate with real outcomes.
Sample Answer
When teams optimize proxies (e.g., click-through rate, predicted relevance score) instead of the true objective (e.g., lifetime value, user retention), Goodhart’s law kicks in: the proxy ceases to be informative because models and people learn to exploit quirks of the proxy rather than driving real value. In AI systems this appears as reward-hacking (models generating superficially high-scoring outputs), dataset-specialization, or surface-level UI changes that boost metrics but harm retention.
Evaluation regime to detect & mitigate gaming:
- Define hierarchical objectives
- Primary business KPIs: retention, LTV, revenue per user, safety incidents.
- Secondary proxies: CTR, predicted relevance: explicitly tagged as proxies.
- Adversarial holdout sets
- Maintain holdout sets crafted adversarially (edge cases, manipulated inputs, distribution shifts).
- Periodically evaluate new models on these sets to reveal brittle optimizations.
- Randomized audits
- Run randomized, blind human audits across outputs (A/B tests with hidden evaluation teams).
- Include synthetic adversarial prompts designed to reveal overfitting to proxies.
- Long-term business metrics & cohort analysis
- Measure downstream outcomes (30/90-day retention, churn, refund rates) per experiment cohort.
- Use uplift modeling to attribute long-term impact vs short-term proxy gains.
- Cross-team guardrails & incentives
- Align incentives: tie engineering/product goals partly to long-term KPIs.
- Require evaluation checklists and sign-offs from analytics, trust/safety, and business stakeholders.
- Continuous monitoring and anomaly detection
- Instrument metric correlations: monitor cases where proxy improves but business KPIs stagnate or decline.
- Build automated detectors for suspicious patterns (sudden localized improvements, distributional changes, surge in edge-case failures) and trigger rollback/hold.
- Use feature-importance drift, calibration checks, and distributional tests (KS, population stability index).
- Investigations & remediation workflow
- On anomaly: run forensic tests (batch vs online, example-level inspection, adversarial inputs), freeze rollout if confirmed, and deploy fixes (regularization, adversarial training, reward reshaping, or revised proxy).
Example: A reranker increases CTR by 15% but cohort retention drops. Investigation reveals click-bait snippets; mitigation included adding a downstream retention objective to training, adversarial holdout of click-bait examples, and human audits: restoring aligned improvements.
This regime blends offline adversarial tests, randomized human checks, long-horizon measurement, organizational incentives, and continuous automated monitoring to detect and reduce metric gaming.
A model's error rate has increased sharply for a particular user segment, or SHAP feature importances have shifted noticeably after a data pipeline change. Describe how you would use SHAP values to perform root-cause analysis: computing per-segment attributions, comparing them to a baseline, and the caveats when features are correlated, and how you would determine whether the shift reflects a real population change, a preprocessing bug, newly introduced leakage, or a training artifact.
Sample Answer
Situation: The model's error rate has jumped for a specific user segment (e.g., users in Region X). I would use SHAP to find which features' contributions changed for that segment versus baseline and identify the likely root cause.
Steps:
- Compute instance-level SHAP
- Use the same explainer used in production (TreeExplainer/DeepExplainer/KernelExplainer) and compute SHAP values for: (a) all instances in the failing segment, (b) a baseline set (historical population or recent non-failing users).
- Aggregate across the segment
- Compute per-feature metrics: mean(SHAP), mean(|SHAP|), median, and the sign proportion (fraction positive vs negative). Capture the distribution (violin/histogram) to see heterogeneity.
- Optionally compute interaction SHAP for top features to detect feature-pair effects.
- Compare to baseline
- For each feature compute delta = metric_segment minus metric_baseline. Rank features by change in mean(|SHAP|) and change in signed mean to see which features increased in influence or flipped direction.
- Run statistical tests (bootstrap CIs, permutation test, or a t-test if assumptions hold) to verify significance and compute effect sizes.
- Distinguishing the four possible root causes explicitly
- Real population change: the segment's INPUT feature distributions genuinely shifted (a new user cohort, a seasonal effect, a new device type). Confirm by comparing feature distributions for the segment across time using the raw, non-model data, independent of SHAP. If the SHAP shift tracks a distribution shift that's externally explainable (a marketing campaign, a product launch, a new region), this is the likely cause, and the fix is usually retraining or reweighting rather than a bug hunt.
- Preprocessing bug: the FEATURE VALUES going into the model changed because of a code or pipeline defect (a join breaking, a null-fill changing, a unit change), not because the real world changed. Confirm by re-running the exact preprocessing code on raw logs captured before and after the suspected change and diffing the outputs field by field; a feature that silently changed shape (a categorical suddenly encoded differently, a numeric field's scale shifted by a constant factor) with no real-world reason is a bug, not a population shift.
- Newly introduced leakage: a feature that was NOT available at the true prediction time is now present, or a previously-masked feature briefly saw future or label-correlated information, causing the model to appear to lean on it more heavily. Confirm by explicitly checking the feature's computation window against the label's timestamp for the affected segment (does it use any event at or after the point the label became known?), and by checking whether the SHAP-flagged feature correlates suspiciously strongly with the label -- near-perfect separation is a leakage tell, not a real signal.
- Training artifact: nothing changed in production data at all; the apparent shift is an artifact of HOW SHAP was computed (a different background/reference dataset between the two runs, a different model version, or a small-sample-size segment producing high-variance attributions). Confirm by recomputing SHAP for both time periods with identical explainer settings, background dataset, and model version, and by bootstrapping the segment's SHAP estimates to see if the 'shift' is within noise.
Only after ruling out the preprocessing-bug, leakage, and training-artifact explanations (all fixable infrastructure issues, not real signal) should the SHAP shift be treated as reflecting a genuine change in the world that the model needs to be retrained or reweighted for.
Caveats when interpreting SHAP changes:
- SHAP is descriptive, not causal: a change in SHAP points to association with model output, not that the feature caused the errors.
- Background/baseline choice matters: SHAP values depend on the background dataset; compare using a consistent baseline or test sensitivity to different baselines.
- Correlated features & interactions: SHAP can apportion importance across correlated inputs but may produce unstable attribution; use interaction SHAP and conditional analyses.
- Sample size and variance: small segments yield high variance; use bootstrap CIs.
- Model changes and explainer consistency: if the model version changed, recompute SHAP with the same explainer settings.
- Computation & approximation: kernel approximations may be noisy; prefer exact explainers for trees or validated approximations.
This process links SHAP-driven signals to a specific, testable root cause among the four candidates above, enabling prioritized, testable remediation (relabeling, retraining, feature fixes, or targeted monitoring) instead of treating every SHAP shift as automatically meaningful.
Unlock Full Question Bank
Get access to all Model Evaluation and Validation interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.