Bird
Raised Fist0

The Feature Importance Mirage

THEORYadvancedInterview freq: high
Choose your preparation mode6 modes available
🐛
The Feature Importance Mirage
Issue started after the latest model deployment two weeks ago.

A credit scoring model used by a financial institution to assess loan applications, processing 500,000 applications per month.

Symptom
Model accuracy remains stable, but recall for high-risk applicants has dropped to 0.
📡
Signals
feature_importance
Feature importance analysis using SHAP values
Feature 'recent_credit_inquiries' importance dropped from 0.25 to 0.01 after deployment
metric
Recall for high-risk applicants
Recall dropped from 0.72 to 0.00
distribution
Distribution of 'recent_credit_inquiries' in the training vs. live data
Live data shows a spike in 'recent_credit_inquiries' at zero, not present in training data
log
Deployment logs for the latest model update
No errors or warnings during deployment
feature_importance
LIME analysis on a subset of predictions
LIME shows 'recent_credit_inquiries' as a non-contributing factor post-deployment
🔬
Hypotheses
The feature 'recent_credit_inquiries' is being misinterpreted due to a data distribution shift.
Feature importance drop in SHAPDistribution shift in 'recent_credit_inquiries'
Verify: Check if the distribution shift aligns with the drop in recall.
import matplotlib.pyplot as plt
plt.hist(live_data['recent_credit_inquiries'], bins=50, alpha=0.5, label='Live')
plt.hist(training_data['recent_credit_inquiries'], bins=50, alpha=0.5, label='Training')
plt.legend(loc='upper right')
plt.show()
The model update inadvertently removed or altered the handling of 'recent_credit_inquiries'.
Feature importance drop in SHAP and LIME
Verify: Review the model code and feature engineering pipeline for changes.
with open('model_code.py', 'r') as file:
    print(file.read())
🎯
Root Cause
A data preprocessing step was altered, causing 'recent_credit_inquiries' to be zeroed out in live data.

A change in the data pipeline during deployment inadvertently zeroed out 'recent_credit_inquiries' for all live data.

🔧
Fix Strategy
ImmediateRollback to the previous model version.
Short-termCorrect the data preprocessing step to handle 'recent_credit_inquiries' correctly.
Long-termImplement a robust data validation step to catch such preprocessing errors before deployment.
🐍
Python Fix
Python
def preprocess_data(data):
    data['recent_credit_inquiries'] = data['recent_credit_inquiries'].fillna(0)
    return data

# Apply the fix to the live data
live_data = preprocess_data(live_data)
✗
Common Wrong Diagnoses
▼ Show
The model is overfitting to the training data.
Why candidates think this: The stable accuracy might suggest overfitting.
Why wrong: Overfitting would not cause a sudden drop in recall for a specific group post-deployment.
The model's hyperparameters are not tuned for recall.
Why candidates think this: Recall drop might suggest poor hyperparameter tuning.
Why wrong: Hyperparameter tuning would not cause a sudden change post-deployment without a model retrain.
📊
Monitoring to Add
  • Monitor distribution of key features in live data vs. training data.
  • Set up alerts for significant drops in feature importance post-deployment.
  • Track recall metrics for high-risk categories continuously.
📋
Process Change

Introduce a mandatory review of data preprocessing steps during model updates.

🏗️
Architectural Change

Implement a shadow deployment environment to test data pipeline changes before full deployment.

💡
Key Insight
Data preprocessing errors can silently alter feature distributions, leading to unexpected model behavior in production.

Practice

(1/5)
1. Given the following Python code snippet, what will be the output if the dataset contains data leakage?
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = LogisticRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print(accuracy_score(y_test, y_pred))
easy
A. The accuracy will be lower than expected.
B. The code will throw an error due to data leakage.
C. The accuracy will be exactly as expected.
D. The accuracy will be higher than expected.

Solution

  1. Step 1: Understand the impact of data leakage

    Data leakage often results in overly optimistic performance metrics.
  2. Step 2: Analyze the code behavior

    The code will execute without errors, but if leakage exists, the model will perform better than it should.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Leakage inflates accuracy [OK]
Hint: Leakage inflates accuracy [OK]
Common Mistakes:
2. When debugging a model with high variance, which approach is more suitable?
medium
A. Increase model complexity
B. Add more training data
C. Reduce regularization
D. Use a smaller model

Solution

  1. Step 1: Identify high variance symptoms

    High variance indicates overfitting, where the model performs well on training data but poorly on unseen data.
  2. Step 2: Choose the right approach

    Adding more training data helps the model generalize better, reducing overfitting.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    High variance = more data [OK]
Hint: High variance = more data [OK]
Common Mistakes:
3. When deciding between offline and online evaluation for a new feature in a web application, which approach is more suitable if user feedback is critical and why?
medium
A. Offline evaluation, because it allows for controlled experiments.
B. Online evaluation, because it captures real user feedback and interaction.
C. Offline evaluation, because it is faster and less resource-intensive.
D. Online evaluation, because it avoids overfitting to historical data.

Solution

  1. Step 1: Identify the need for user feedback.

    When user feedback is critical, capturing real interactions is essential.
  2. Step 2: Evaluate the suitability of each approach.

    Offline evaluation, because it allows for controlled experiments. is incorrect because controlled experiments do not capture real-time feedback. Offline evaluation, because it is faster and less resource-intensive. is incorrect because speed and resource usage do not address feedback needs. Online evaluation, because it avoids overfitting to historical data. is partially correct but does not emphasize feedback.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Real feedback needs online evaluation. [OK]
Hint: Real feedback needs online evaluation. [OK]
Common Mistakes:
4. When considering bias mitigation strategies, which approach is more suitable for a scenario where you cannot alter the training data but need to ensure fairness in predictions?
medium
A. Pre-processing techniques
B. In-processing techniques
C. Data augmentation
D. Post-processing techniques

Solution

  1. Step 1: Identify the constraint.

    Cannot alter training data, need fairness in predictions.
  2. Step 2: Choose the suitable technique.

    Post-processing techniques adjust predictions to ensure fairness without altering the model or data.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Post-processing adjusts predictions, not data. [OK]
Hint: Post-processing adjusts predictions, not data. [OK]
Common Mistakes:
5. 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:
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