Bird
Raised Fist0

Offline vs Online Evaluation - Why They Disagree

THEORYadvancedInterview freq: very_high
Choose your preparation mode6 modes available
🐛
The AUC Discrepancy Mystery
Started immediately after the latest model deployment last Friday.

A recommendation system model serving 5M users daily, designed to predict user engagement with content.

Symptom
Model achieves 0.92 AUC offline but drops to 0.75 AUC on live traffic.
📡
Signals
metric
Offline AUC from validation dataset
0.92 consistently over the last month
metric
Online AUC from live traffic
Dropped to 0.75 after last Friday's deployment
feature_importance
Feature importance ranking from the model
Feature 'user_last_active_days' dropped from rank #3 (0.15) to rank #20 (0.01) post-deploy
distribution
Distribution of 'user_last_active_days' feature in live data
Shifted significantly after deployment
log
Deployment logs for the latest model update
No errors or warnings during deployment
🔬
Hypotheses
The model is overfitting to the offline validation data.
Offline AUC is high but online AUC is low
Verify: Check if the validation data distribution matches the training data too closely.
import numpy as np
np.mean(train_data['user_last_active_days']) == np.mean(validation_data['user_last_active_days'])
Feature 'user_last_active_days' has a different distribution in live data.
Feature importance dropDistribution shift
Verify: Compare the distribution of 'user_last_active_days' in training and live data.
import matplotlib.pyplot as plt
plt.hist(live_data['user_last_active_days'], alpha=0.5, label='Live')
plt.hist(train_data['user_last_active_days'], alpha=0.5, label='Train')
plt.legend()
🎯
Root Cause
The feature 'user_last_active_days' has a different distribution in live data compared to training data.

A recent change in user engagement patterns was not reflected in the training data, causing the model to misinterpret this feature online.

🔧
Fix Strategy
ImmediateRollback to the previous model version that had stable online AUC.
Short-termUpdate the training dataset to include recent user engagement patterns.
Long-termImplement a continuous data pipeline that updates training data with recent user behavior.
🐍
Python Fix
Python
def update_training_data(live_data, train_data):
    recent_data = live_data[live_data['date'] > '2023-10-01']
    updated_train_data = pd.concat([train_data, recent_data])
    return updated_train_data

train_data = update_training_data(live_data, train_data)
✗
Common Wrong Diagnoses
▼ Show
The model has a bug in the deployment code.
Why candidates think this: Deployment issues are common causes of discrepancies.
Why wrong: Deployment logs show no errors, and the issue is data-related, not code-related.
The model is underfitting the data.
Why candidates think this: Low online AUC might suggest underfitting.
Why wrong: High offline AUC indicates the model fits the training data well; the issue is with data mismatch.
📊
Monitoring to Add
  • Monitor distribution shifts in key features between training and live data.
  • Set up alerts for significant drops in online AUC.
  • Track feature importance changes post-deployment.
📋
Process Change

Incorporate regular updates to the training dataset with recent live data snapshots.

🏗️
Architectural Change

Design the system to automatically retrain models with updated data reflecting current user behavior.

💡
Key Insight
Offline evaluation can mask data distribution shifts that only become apparent in live environments.

Practice

(1/5)
1. Given the following Python code snippet, what will be the output if the input data has undergone covariate drift?
import numpy as np
from sklearn.linear_model import LinearRegression

X_train = np.array([[1, 2], [2, 3], [3, 4]])
y_train = np.array([3, 5, 7])
model = LinearRegression().fit(X_train, y_train)

X_test = np.array([[4, 5], [5, 6]])
predictions = model.predict(X_test)
print(predictions)
easy
A. The predictions will be accurate.
B. The model will throw an error.
C. The predictions will be unaffected by covariate drift.
D. The predictions will be biased due to covariate drift.

Solution

  1. Step 1: Understand the impact of covariate drift.

    Covariate drift affects the input distribution, leading to biased predictions.
  2. Step 2: Eliminate wrong options.

    The model won't throw an error (The model will throw an error.) and predictions won't be accurate (The predictions will be accurate.) or unaffected (The predictions will be unaffected by covariate drift.) due to drift.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Covariate drift biases predictions [OK]
Hint: Covariate drift biases predictions [OK]
Common Mistakes:
2. A model trained on a dataset with engineered features is underperforming on the validation set. What is the most likely cause?
medium
A. The model is too simple for the complexity of the features.
B. The features are over-engineered, causing overfitting.
C. The model has too many hyperparameters to tune.
D. The features are not normalized, leading to poor model performance.

Solution

  1. Step 1: Analyze the symptoms of underperformance.

    Underperformance on validation suggests overfitting or poor generalization.
  2. Step 2: Evaluate the role of feature engineering.

    Over-engineered features (C) can lead to overfitting, especially if they capture noise. Normalization (B) affects convergence but not generalization directly. Model complexity (A, D) is less likely the issue if features are the focus.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Over-engineered features often lead to overfitting. [OK]
Hint: Over-engineered features often lead to overfitting. [OK]
Common Mistakes:
3. When choosing between online and offline data collection for a recommendation system, which factor is most critical for deciding to use online data collection?
medium
A. The need for real-time user feedback integration.
B. The availability of large historical datasets.
C. The requirement for high computational resources.
D. The simplicity of the data processing pipeline.

Solution

  1. Step 1: Identify the key factor for online data collection

    Online data collection is crucial when real-time feedback is needed to update recommendations dynamically.
  2. Step 2: Eliminate factors not specific to online collection

    Options B, C, and D do not specifically require online data collection; they can be addressed with offline methods.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Real-time needs = online collection. [OK]
Hint: Real-time needs = online collection. [OK]
Common Mistakes:
4. When dealing with high-dimensional data, which approach is more suitable for reducing dimensionality while preserving variance?
medium
A. Use k-means clustering to group similar data points.
B. Use L1 regularization to select features.
C. Apply PCA to project data onto a lower-dimensional space.
D. Apply dropout to randomly ignore features during training.

Solution

  1. Step 1: Identify the goal of preserving variance.

    PCA is designed to reduce dimensions while preserving variance.
  2. Step 2: Eliminate wrong options.

    Use L1 regularization to select features. selects features, not reduce dimensions. Use k-means clustering to group similar data points. clusters data, not reduce dimensions. Apply dropout to randomly ignore features during training. is for regularization, not dimensionality reduction.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    PCA reduces dimensions, keeps variance. [OK]
Hint: PCA reduces dimensions, keeps variance. [OK]
Common Mistakes:
5. You are tasked with designing a CNN for a medical imaging application where interpretability is crucial. Which approach would best leverage the inductive bias of CNNs for this task?
hard
A. Use networks with small kernels and more layers to capture local patterns
B. Use shallow networks with large kernels to capture global patterns
C. Use networks with attention mechanisms to highlight important regions
D. Use very deep networks to capture complex patterns

Solution

  1. Step 1: Consider interpretability needs

    Small kernels with more layers help capture local patterns, which are crucial for interpretability in medical imaging.
  2. Step 2: Eliminate wrong options

    Use very deep networks to capture complex patterns is incorrect because very deep networks can be less interpretable. Use shallow networks with large kernels to capture global patterns is incorrect as large kernels reduce local detail capture. Use networks with attention mechanisms to highlight important regions is incorrect because attention mechanisms, while useful, are not leveraging CNN's inductive bias.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Small kernels capture local details, aiding interpretability. [OK]
Hint: Small kernels capture local details, aiding interpretability. [OK]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard