# 漂移检测（机器学习）

漂移检测是一类监控方法，它观察输入数据或已部署模型的行为是否存在分布变化，并在模型可能需要重新训练时发出信号。在在线监督学习中，概念漂移是指输入数据与目标变量之间关系随时间的变化。<sup>[1](https://dl.acm.org/doi/10.1145/2523813)</sup> 将联合分布写作 \( P(x, y) = P(x) \cdot P(y \mid x) \)，协变量漂移在 \( P(y \mid x) \) 保持不变的情况下移动输入边缘分布 \( P(x) \)，概念漂移移动的是 \( P(y \mid x) \) 本身，而标签漂移移动的是目标边缘分布 \( P(y) \)。<sup>[2](http://temporalbook.apartsin.com/part-5-uncertainty-online-adaptive/module-21-adaptive-systems/section-21.2.html)</sup> 条件分布的变化称为真实漂移；边缘分布的变化称为虚拟漂移或数据漂移。<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC11294200/)</sup>

| 关键事实 | 数值或陈述 | 来源 |
|---|---|---|
| 检测器监控什么 | 三个层次：输入漂移（无需标签）、预测漂移（仅模型输出）、性能漂移（需要标签） | <sup>[2](http://temporalbook.apartsin.com/part-5-uncertainty-online-adaptive/module-21-adaptive-systems/section-21.2.html)</sup> |
| 真实漂移与虚拟漂移 | 真实漂移改变 \( P(y \mid x) \)；虚拟漂移或数据漂移改变 \( P(x) \) | <sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC11294200/)</sup> |
| DDM阈值 | 警告阈值 \( p_{t} + s_{t} \ge p_{\min} + 2 \times s_{\min} \)，漂移阈值 \( p_{t} + s_{t} \ge p_{\min} + 3 \times s_{\min} \) | <sup>[4](https://www.mdpi.com/2078-2489/15/12/786)</sup> |
| ADWIN2开销 | 摊还内存与更新时间 \( O(\log W) \)；每个样本最坏情况 \( O(\log^{2} W) \) | <sup>[5](https://epubs.siam.org/doi/10.1137/1.9781611972771.42)</sup><sup> • </sup><sup>[6](https://link.springer.com/content/pdf/10.1007/s42452-019-1433-0.pdf)</sup> |
| 检测延迟下界 | 当 \( \gamma \to \infty \) 时，\( \mathrm{EDD} \ge (\log \gamma) \, (1 + o(1)) / D(f_{1} \| f_{0}) \)；等号仅在渐近意义下由最优程序达到 | <sup>[7](https://arxiv.org/pdf/2210.05181)</sup> |
| 多重检验风险 | 在 \( \alpha = 0.05 \) 下对200个特征做KS检验：误报概率 \( 1 - 0.95^{200} \approx 0.99997 \) | <sup>[2](http://temporalbook.apartsin.com/part-5-uncertainty-online-adaptive/module-21-adaptive-systems/section-21.2.html)</sup> |
| 软件 | MOA（Java）、scikit-multiflow、Frouros、Alibi-Detect（Python）、datadriftR（R） | <sup>[8](https://joss.theoj.org/papers/10.21105/joss.09481.pdf)</sup><sup> • </sup><sup>[9](https://frouros.readthedocs.io/en/stable/index.html)</sup><sup> • </sup><sup>[10](https://docs.seldon.ai/alibi-detect/cd/methods/online/onlinemmddrift)</sup> |

## 工作原理

序贯[变点检测](https://www.edgepedia.org/zh/change-point-detection)提供了统计核心。检测器是一个停止时间：在第 \( t \) 个样本之后决定停止，仅取决于迄今观察到的历史，而阈值 \( b \) 在误报率与检测延迟之间取得平衡。两个标准的性能指标是平均运行长度（ARL），即变化前分布下的期望停止时间，以及期望检测延迟（EDD）。<sup>[7](https://arxiv.org/pdf/2210.05181)</sup> 对于变化前和变化后的分布 \( f_{0} \) 与 \( f_{1} \)，其Kullback-Leibler散度（衡量两个概率分布差异程度的量）为 \( D(f_{1} \| f_{0}) \)，著名的下界是：当 \( \gamma \to \infty \) 时，\( \mathrm{EDD} \ge (\log \gamma) \, (1 + o(1)) / D(f_{1} \| f_{0}) \)，其中 \( \gamma \) 界定ARL；等号仅在渐近意义下由最优程序达到，且两个分布重叠越多，任何检测器所能达到的检测速度就越慢。<sup>[7](https://arxiv.org/pdf/2210.05181)</sup>

大多数实用检测器遵循四阶段方案：窗口选择、描述子构建、相异度分数计算，以及归一化或假设检验。<sup>[11](https://www.frontiersin.org/journals/artificial-intelligence/articles/10.3389/frai.2024.1330257/full)</sup> 双窗口范式用非参数检验将固定的参考窗口与滑动的当前窗口进行比较，并在灵敏度、误报和运行时间方面具有已证明的保证。<sup>[12](https://www.vldb.org/conf/2004/RS5P1.PDF)</sup>

## 实施方法

**根据标签可得性选择监控层。** 输入漂移不需要标签，也不需要模型输出，只需要请求；预测漂移需要模型输出，但仍不需要标签；性能漂移需要稀缺的标签。成熟的监控器将输入和预测作为常开的预警层运行，将性能作为较慢的权威确认。<sup>[2](http://temporalbook.apartsin.com/part-5-uncertainty-online-adaptive/module-21-adaptive-systems/section-21.2.html)</sup>

**配置窗口与阈值。** 选择参考窗口策略（固定、滑动、蓄水池汇集或自适应）。<sup>[13](https://link.springer.com/content/pdf/10.1007/s41060-024-00620-y.pdf)</sup> 诸如Alibi-Detect的在线MMD之类的在线核检测器，根据期望运行时间（ERT）——即检测器在发生一次误检之前平均应无漂移运行的时间步数——加上测试窗口大小来设定阈值；较小的窗口对严重漂移响应更快，较大的窗口对轻微漂移具有更强的检验力。<sup>[10](https://docs.seldon.ai/alibi-detect/cd/methods/online/onlinemmddrift)</sup> 错误率检测器使用两个级别：DDM的警告级别提示准备新模型，其漂移级别则替换当前模型。<sup>[4](https://www.mdpi.com/2078-2489/15/12/786)</sup>

**对警报进行分诊处理。** 红色警报下的重新训练应经过分诊，以区分真实偏移与数据质量故障，并设置冷却期、要求漂移在连续多个窗口中持续存在，以及在触发阈值与解除阈值之间设置滞回间隙以抑制振荡。所有检测器都存在从性能退化开始到警报之间的反应滞后，在此期间模型已经退化。<sup>[2](http://temporalbook.apartsin.com/part-5-uncertainty-online-adaptive/module-21-adaptive-systems/section-21.2.html)</sup>

## 起源

其谱系始于统计过程控制：E. S. 佩奇（E. S. Page）1954年发表在《[生物计量学](https://www.edgepedia.org/zh/biometrika)》（Biometrika）上关于连续检验方案的论文引入了CUSUM，即累积和方案，它是Page-Hinkley漂移检验的前身。<sup>[14](https://doi.org/10.1093/biomet/41.1-2.100)</sup> 戴维·P·赫尔姆博尔德（David P. Helmbold）与菲利普·M·朗（Philip M. Long）1994年发表在《机器学习》（Machine Learning）上的论文《通过最小化分歧追踪漂移概念》（Tracking Drifting Concepts By Minimizing Disagreements），是关于漂移概念下学习的早期理论工作。<sup>[15](https://doi.org/10.1023/a:1022694620923)</sup> 杰弗里·I·韦布（Geoffrey I. Webb）及其同事在2016年《数据挖掘与知识发现》（Data Mining and Knowledge Discovery）的一篇论文中刻画了概念漂移。<sup>[16](https://doi.org/10.1007/s10618-015-0448-4)</sup> 戈登·J·罗斯（Gordon J. Ross）及其同事于2012年在《模式识别快报》（Pattern Recognition Letters）上引入了用于概念漂移的指数加权移动平均图（2011年在线发表），<sup>[17](https://doi.org/10.1016/j.patrec.2011.08.019)</sup> 罗伯托·S. M. 巴罗斯（Roberto S.M. Barros）及其同事于2017年在《专家系统与应用》（Expert Systems with Applications）上引入了反应式漂移检测方法RDDM，<sup>[18](https://doi.org/10.1016/j.eswa.2017.08.023)</sup> 维托尔·塞尔凯拉（Vitor Cerqueira）及其同事于2022年在《机器学习》（Machine Learning）上引入了用于无监督概念漂移检测的师生方法STUDD。<sup>[19](https://doi.org/10.1007/s10994-022-06188-7)</sup>

## 变体

**错误率检测器**消费二元（0/1）错误流。<sup>[8](https://joss.theoj.org/papers/10.21105/joss.09481.pdf)</sup> DDM仅存储错误率 \( p_{t} \) 和标准差 \( s_{t} = \sqrt{p_{t}(1 - p_{t})/t} \)，使其几乎无记忆，并在上述警告阈值和漂移阈值处触发。<sup>[6](https://link.springer.com/content/pdf/10.1007/s42452-019-1433-0.pdf)</sup><sup> • </sup><sup>[4](https://www.mdpi.com/2078-2489/15/12/786)</sup> 它对实时使用效率很高，但在噪声环境中会产生误报，且难以应对渐变漂移；一个主要缺陷是它只适用于突变漂移，渐变漂移会被缓慢检测到或漏检。<sup>[4](https://www.mdpi.com/2078-2489/15/12/786)</sup><sup> • </sup><sup>[6](https://link.springer.com/content/pdf/10.1007/s42452-019-1433-0.pdf)</sup> EDDM则监控两次误分类错误之间的距离，但要求至少30个错误，这在类别不平衡的数据集上会带来问题。<sup>[6](https://link.springer.com/content/pdf/10.1007/s42452-019-1433-0.pdf)</sup>

**窗口化与累积和检测器**作用于数值流。ADWIN维护一个可变大小的窗口，数据平稳时窗口增长，发生变化时窗口收缩，并比较所有子窗口对的均值，其作者认为这比对照历史最小值监控错误率能更快地检测；它对假阳性和假阴性率提供了界，而高效的ADWIN2以 \( O(\log W) \) 的内存和更新时间维护长度为 \( W \) 的窗口。<sup>[5](https://epubs.siam.org/doi/10.1137/1.9781611972771.42)</sup> HDDM-A与HDDM-W将Hoeffding界自适应窗口应用于均值偏移，KSWIN则是滑动窗口Kolmogorov-Smirnov检验。<sup>[8](https://joss.theoj.org/papers/10.21105/joss.09481.pdf)</sup>

**批处理与无监督检测器**比较留出的参考窗口与测试窗口。Frouros的批处理目录涵盖距离度量（巴塔查里亚距离、推土机距离、能量距离、海林格距离、Jensen-Shannon散度、KL散度、最大均值差异、群体稳定性指数）和统计检验（安德森-达林检验、卡方检验、Kolmogorov-Smirnov检验、曼-惠特尼U检验、韦尔奇t检验等）。<sup>[9](https://frouros.readthedocs.io/en/stable/index.html)</sup> 在线MMD检测器通过再生核[希尔伯特空间](https://www.edgepedia.org/zh/hilbert-space)中的均值嵌入 \( \mu_{p} \) 与 \( \mu_{q} \)，计算参考样本与测试窗口之间的平方MMD，默认使用径向基函数核。<sup>[10](https://docs.seldon.ai/alibi-detect/cd/methods/online/onlinemmddrift)</sup> kdq树将分布划分为更小的子结构，并用Kullback-Leibler距离比较先前窗口与当前窗口。<sup>[20](https://mdpi-res.com/d_attachment/applsci/applsci-12-11688/article_deploy/applsci-12-11688.pdf?version=1668687321)</sup>

**库。** 流式检测器已在[Java](https://www.edgepedia.org/zh/java-software-platform)（MOA）和Python（scikit-multiflow）中广泛可用，而R生态一直缺乏专用包，直到乌古尔·达尔（Ugur Dar）与穆斯塔法·查武什（Mustafa Cavus）推出datadriftR（《开源软件杂志》，Journal of Open Source Software，2026），它实现了DDM、EDDM、HDDM-A/W、ADWIN、KSWIN、Page-Hinkley检验、KL散度监控以及一种轮廓比较方法。<sup>[8](https://joss.theoj.org/papers/10.21105/joss.09481.pdf)</sup><sup> • </sup><sup>[21](https://doi.org/10.21105/joss.09481)</sup>

## 应用

已发表的比较集中在两个领域。在信用风险与金融领域，群体稳定性指数无处不在：它将两个样本分入参考样本的分位数箱，并对各箱的对称相对熵项求和。<sup>[2](http://temporalbook.apartsin.com/part-5-uncertainty-online-adaptive/module-21-adaptive-systems/section-21.2.html)</sup> 在自然语言处理中，DriftWatch使用句法词汇频率检测器、基于VAE的S-BERT句向量语义检测器以及预测熵概念漂移检测，来检测文本数据中的协变量漂移和概念漂移，并且还实现了基于大语言模型的零样本漂移检测。<sup>[22](https://aclanthology.org/2024.naacl-industry.28.pdf)</sup> 对于部署的30亿至320亿参数的大语言模型，对模型输出的共形检验鞅可检测标签偏移，同时控制误报率。<sup>[23](https://proceedings.mlr.press/v329/bostrom26b.html)</sup>

## 局限与替代方案

**每个监控层都有盲区。** 诸如DDM和EDDM之类基于性能的检测器对受监控错误率的变化作出响应：它们可能在机制未变的纯协变量流上报警，也可能漏掉那些不改变错误率的 \( P(Y \mid X) \) 变化；仅监控输入空间的基于分布的检测器无法检测仅影响标注机制的真实漂移，例如类别互换。<sup>[24](https://www.computer.org/csdl/api/v1/periodical/trans/tk/5555/01/09540313/1wWCbw0OpH2/download-article/pdf)</sup> 无监督检测器仅在特征空间上运行，除非后验漂移伴随协变量偏移，否则无法检测到它。<sup>[13](https://link.springer.com/content/pdf/10.1007/s41060-024-00620-y.pdf)</sup>

**漂移形态与维度很重要。** 所有被评估的方法在高维情况下都严重受损；当误报代价高昂时，应避免逐维方法，而建议改用预处理或特征选择。<sup>[11](https://www.frontiersin.org/journals/artificial-intelligence/articles/10.3389/frai.2024.1330257/full)</sup> 单变量逐特征检验对多变量漂移视而不见，例如使每个边缘分布都不变的相关系数符号翻转；MMD是能看到完整联合分布的标准无标签检测器。<sup>[2](http://temporalbook.apartsin.com/part-5-uncertainty-online-adaptive/module-21-adaptive-systems/section-21.2.html)</sup>

**替代方案也有其局限。** 比费（Bifet）证明，每处理 \( n \) 个样本就用简单的方法调整分类器，可能优于复杂的检测方法，因此仅比较预测性能不足以评判检测器。<sup>[13](https://link.springer.com/content/pdf/10.1007/s41060-024-00620-y.pdf)</sup> 诸如NannyML的CBPE之类依赖校准后预测概率的无标签性能估计，对概念漂移造成的性能损失视而不见，因为其校准假设恰好在概念漂移下失效。<sup>[2](http://temporalbook.apartsin.com/part-5-uncertainty-online-adaptive/module-21-adaptive-systems/section-21.2.html)</sup> 基于损失的漂移解释同样不可靠：总存在影响最优决策边界的纯虚拟漂移，以及在有限VC维下既不影响边界也不影响最优模型损失的真实漂移。<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC11294200/)</sup>

## References

1. [A survey on concept drift adaptation (Gama et al., ACM Computing Surveys 2014)](https://dl.acm.org/doi/10.1145/2523813)
2. [Section 21.2: Drift Detection in Production, Building Temporal AI](http://temporalbook.apartsin.com/part-5-uncertainty-online-adaptive/module-21-adaptive-systems/section-21.2.html)
3. [One or two things we know about concept drift, Part B: locating and explaining concept drift (Frontiers in AI, 2024)](https://pmc.ncbi.nlm.nih.gov/articles/PMC11294200/)
4. [Evolving Strategies in Machine Learning: A Systematic Review of Concept Drift Detection (Information, MDPI, 2024)](https://www.mdpi.com/2078-2489/15/12/786)
5. [Learning from Time-Changing Data with Adaptive Windowing (Bifet & Gavaldà, SDM 2007)](https://epubs.siam.org/doi/10.1137/1.9781611972771.42)
6. [Data stream mining: methods and challenges for handling concept drift (Discover Applied Sciences, 2019)](https://link.springer.com/content/pdf/10.1007/s42452-019-1433-0.pdf)
7. [Sequential Change-Point Detection: A Survey/Tutorial](https://arxiv.org/pdf/2210.05181)
8. [datadriftR: An R package for data drift detection (Journal of Open Source Software, Dar & Cavus, 11(119):9481, DOI 10.21105/joss.09481)](https://joss.theoj.org/papers/10.21105/joss.09481.pdf)
9. [Frouros documentation, drift detector taxonomy](https://frouros.readthedocs.io/en/stable/index.html)
10. [Alibi-Detect online MMD drift detector (documentation)](https://docs.seldon.ai/alibi-detect/cd/methods/online/onlinemmddrift)
11. [One or two things we know about concept drift, Part A: detecting concept drift (Frontiers in AI, 2024)](https://www.frontiersin.org/journals/artificial-intelligence/articles/10.3389/frai.2024.1330257/full)
12. [Detecting Change in Data Streams (Kifer, Ben-David, Gehrke, VLDB 2004)](https://www.vldb.org/conf/2004/RS5P1.PDF)
13. [A benchmark and survey of fully unsupervised concept drift detectors on real-world data streams (Int. J. Data Science and Analytics, 2024)](https://link.springer.com/content/pdf/10.1007/s41060-024-00620-y.pdf)
14. [E. S. PAGE (1954). CONTINUOUS INSPECTION SCHEMES. Biometrika.](https://doi.org/10.1093/biomet/41.1-2.100)
15. [David P. Helmbold, Philip M. Long (1994). Tracking Drifting Concepts By Minimizing Disagreements. Machine Learning.](https://doi.org/10.1023/a:1022694620923)
16. [Geoffrey I. Webb and colleagues (2016). Characterizing concept drift. Data Mining and Knowledge Discovery.](https://doi.org/10.1007/s10618-015-0448-4)
17. [Gordon J. Ross and colleagues (2011). Exponentially weighted moving average charts for detecting concept drift. Pattern Recognition Letters.](https://doi.org/10.1016/j.patrec.2011.08.019)
18. [Roberto S.M. Barros and colleagues (2017). RDDM: Reactive drift detection method. Expert Systems with Applications.](https://doi.org/10.1016/j.eswa.2017.08.023)
19. [Vitor Cerqueira and colleagues (2022). STUDD: a student–teacher method for unsupervised concept drift detection. Machine Learning.](https://doi.org/10.1007/s10994-022-06188-7)
20. [An Experimental Analysis of Drift Detection Methods on Multi-Class Imbalanced Data Streams (Applied Sciences, MDPI, 2022)](https://mdpi-res.com/d_attachment/applsci/applsci-12-11688/article_deploy/applsci-12-11688.pdf?version=1668687321)
21. [Ugur Dar, Mustafa Cavus (2026). datadriftR: An R package for data drift detection. The Journal of Open Source Software.](https://doi.org/10.21105/joss.09481)
22. [DriftWatch: A Tool that Automatically Detects Data Drift and Extracts Representative Examples Affected by Drift (NAACL 2024 Industry Track)](https://aclanthology.org/2024.naacl-industry.28.pdf)
23. [Detecting Label Shift for Large Language Models with Conformal Test Martingales (PMLR v329, 2026)](https://proceedings.mlr.press/v329/bostrom26b.html)
24. [Hierarchical Reduced-space Drift Detection (HRDD) for supervised data streams (IEEE TKDE, early access)](https://www.computer.org/csdl/api/v1/periodical/trans/tk/5555/01/09540313/1wWCbw0OpH2/download-article/pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/drift-detection-machine-learning

English original: https://www.edgepedia.org/drift-detection-machine-learning
