Catch train-serving skew in feature pipelines
Train-serving skew happens when the serving code computes a feature differently from the training pipeline. A standard check logs features at serving time and compares them with the offline pipeline's values for the same request ids.
Write skew_report(offline, online, tol) where offline and online map request id -> dict of feature name -> float. For ids present in BOTH, compare every feature present in both dicts. Return a dict feature -> mismatch rate (mismatches / comparisons) for every compared feature, where a mismatch is abs(a - b) > tol * max(1, abs(a)). Also include "_missing_online", the fraction of offline ids absent online. Round nothing.
def skew_report(offline, online, tol)Understand the idea
Train-serving skew happens when the live service computes a feature differently from the training pipeline, so the model sees inputs it never learned on. The check: log features at serving time and compare them with offline values for the same request ids. Use a relative tolerance so tiny float noise on big numbers is not flagged: a mismatch is |a - b| > tol x max(1, |a|). Worked example, tol = 0.01. Offline: id 1 {age 30, spend 1000}, id 2 {age 40}, id 3 {age 50}. Online: id 1 {age 30, spend 1000.4}, id 2 {age 41}. Compare ids 1 and 2. Spend: |1000 - 1000.4| = 0.4, allowed 10, fine, so rate 0 / 1 = 0. Age: id 1 matches; id 2 differs by 1, allowed 0.4, mismatch, so rate 1 / 2 = 0.5. Id 3 is missing online: _missing_online = 1 / 3 = 0.333. Rule: per feature, mismatch rate = mismatches / comparisons over shared ids and shared features, plus the fraction of offline ids absent online. Feature stores and ML platforms run such checks.