Neural Mastery
← Practice
Feature Skew Detection Between Training and Servingmedium

Feature Skew Detection Between Training and Serving

medium ML Systems & MLOps 15 min

NumPy allowed · plain Python earns 10 bonus points

Implement real training/serving skew detection: comparing each feature's mean between the training set and live traffic to catch a genuinely common, silent production bug.

Task

Implement detect_feature_skew(train_stats, serving_stats, threshold_pct). Both dicts map feature name -> its mean value. For each feature present in BOTH dicts, compute relative change abs(serving - train) / abs(train) * 100 (skip a feature if train's value is exactly 0, to avoid division by zero). Return a sorted list of feature names where that relative change EXCEEDS threshold_pct.

Function Signature

detect_feature_skew(train_stats: dict[str, float], serving_stats: dict[str, float], threshold_pct: float) -> list[str]

Examples

Example 1: no significant skew
Input: train_stats = {'age': 30} serving_stats = {'age': 31} threshold_pct = 10
Output: []
Example 2: significant skew flagged
Input: train_stats = {'age': 30} serving_stats = {'age': 60} threshold_pct = 10
Output: ['age']
Example 3: multiple features, some skewed
Input: train_stats = {'a': 10, 'b': 100} serving_stats = {'a': 10.5, 'b': 200} threshold_pct = 20
Output: ['b']

Constraints

  • threshold_pct >= 0
Python3Saved ✓
def detect_feature_skew(train_stats, serving_stats, threshold_pct):
# Your implementation here
pass

Case 1: no significant skew
Input: train_stats = {'age': 30} serving_stats = {'age': 31} threshold_pct = 10
Expected: []
Case 2: significant skew flagged
Input: train_stats = {'age': 30} serving_stats = {'age': 60} threshold_pct = 10
Expected: ['age']
Case 3: multiple features, some skewed
Input: train_stats = {'a': 10, 'b': 100} serving_stats = {'a': 10.5, 'b': 200} threshold_pct = 20
Expected: ['b']