M2-016Medium数据质量 · Data quality🔥 大厂高频出现 2 次
做同比/环比时,如何处理季节性?
How do you handle seasonality when computing year-over-year or week-over-week changes?
💡 考场高分一句话答案:
用“去年同期”做同比、用“周内同一天”做环比,或用 STL/回归去掉季节成分后再比较。
Compare with the same period last year for YoY and the same weekday for WoW, or remove the seasonal component with STL or regression before comparing.
📌 核心考察要点 (Key Points)
- 同比(YoY):消除年度季节性,但受去年异常事件影响
- 环比(WoW):用上周同一天而非昨天,消除周内模式
- 分解:$Y_t=T_t+S_t+R_t$,用 STL 分离趋势/季节/残差,看残差是否有异常
- 事件日历:把节假日、促销、大事件作为协变量显式建模
- YoY: removes annual seasonality but is distorted by anomalies in the base year
- WoW: compare with the same weekday last week, not with yesterday, to remove the intra-week pattern
- Decomposition: $Y_t=T_t+S_t+R_t$, use STL to separate trend, season and residual, then look for anomalies in the residual
- Event calendar: model holidays, promotions and major events as explicit covariates
📐 第一性原理与数理推导机理
STL(Seasonal-Trend decomposition using Loess)把序列拆成趋势、季节、残差。异常检测应在残差上做,而不是在原始序列上——否则每次节假日都会误报。判据:残差超过 3 倍 MAD(中位数绝对偏差)即视为异常。
⚖️ 业务权衡与取舍 (Trade-offs & Calibration)
面试里更实用的说法是“我会用上周同日 + 去年同期双基准,并在有异常时看事件日历”。这比讲 STL 更接地气,也更能体现你做过真实报表。
⚠️ 常见高频面试陷阱与避坑指南
- 用“昨天 vs 今天”做环比——周内模式会造成系统性误判
- 把节假日当成异常,反复误报导致告警疲劳
🔍 大厂面试官连环追问 (Follow-ups)
- 如何检测“季节性本身发生了变化”?
- 如果同比和环比给出相反结论,你信哪个?
🎯 关联大厂考题实战训练 (2 题)
嫌字多看太累?进入苏格拉底式对话推演实验室
零打字负担,以大厂考官真实困境切入,通过点选直觉选项暴露思维盲区,手把手推导 Why。
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.