
用于异常值、对抗性和漂移检测的算法
Alibi Detect 是一个源码可用的 Python 库,专注于异常值、对抗性和漂移检测。该包旨在覆盖适用于表格数据、文本、图像和时间序列的在线和离线检测器。漂移检测同时支持 TensorFlow 和 PyTorch 后端。
如需了解更多有关在生产环境中监测异常值和分布的重要性的背景信息,请查看来自 ICML 2020 研讨会 机器学习系统的部署与监测挑战 上的这个演讲,该演讲基于论文生产环境中模型的监测与可解释性并引用了 Alibi Detect。
如需全面了解漂移检测,请观看保护你的机器学习免受漂移影响:入门。该演讲涵盖了漂移是什么以及为什么值得检测、漂移的不同类型、如何以系统的方式检测漂移,并剖析了漂移检测器的内部构造。
该包 alibi-detect 可以从以下位置安装:
pip)conda/mamba)
Prophet 时间序列异常值检测器: ```bash
pip install alibi-detect[prophet]
要从 conda-forge 安装,建议使用 mamba, 可以通过以下命令将其安装到 base conda 环境中:```bash conda install mamba -n base -c conda-forge
要安装 alibi-detect:```bash
mamba install -c conda-forge alibi-detect
我们将使用 VAE 异常检测器 来说明该 API。```python from alibi_detect.od import OutlierVAE from alibi_detect.saving import save_detector, load_detector
od = OutlierVAE(threshold=0.1, encoder_net=encoder_net, decoder_net=decoder_net, latent_dim=1024) od.fit(x_train)
preds = od.predict(x_test)
filepath = './my_detector/' save_detector(od, filepath) od = load_detector(filepath)
预测结果以字典形式返回,键为 `meta` 和 `data`。`meta` 包含检测器的元数据,而 `data` 本身是一个包含实际预测结果的字典。其中包含异常、对抗或漂移的分数与阈值,以及诸如实例是否为异常值之类的预测。不同方法的具体细节可能略有差异,因此我们建议读者熟悉[支持的算法类型](https://docs.seldon.io/projects/alibi-detect/en/stable/overview/algorithms.html)。
## 支持的算法
下表展示了每种算法的建议使用场景。*特征级别* 列表示检测是否可以在特征级别上执行,例如对图像的逐像素检测。有关更多信息,请查阅[算法参考列表](#reference-list),其中包含文档和原始论文的链接以及各检测器的示例。
### 异常检测
| 检测器 | 表格数据 | 图像 | 时间序列 | 文本 | 类别特征 | 在线 | 特征级别 |
|:---------------------|:-------:|:-----:|:-----------:|:----:|:--------------------:|:------:|:-------------:|
| Isolation Forest | ✔ | | | | ✔ | | |
| Mahalanobis Distance | ✔ | | | | ✔ | ✔ | |
| AE | ✔ | ✔ | | | | | ✔ |
| VAE | ✔ | ✔ | | | | | ✔ |
| AEGMM | ✔ | ✔ | | | | | |
| VAEGMM | ✔ | ✔ | | | | | |
| Likelihood Ratios | ✔ | ✔ | ✔ | | ✔ | | ✔ |
| Prophet | | | ✔ | | | | |
| Spectral Residual | | | ✔ | | | ✔ | ✔ |
| Seq2Seq | | | ✔ | | | | ✔ |
### 对抗性检测
| 检测器 | 表格数据 | 图像 | 时间序列 | 文本 | 类别特征 | 在线 | 特征级别 |
| :--- | :---: | :---: |:-----------:|:----:|:--------------------:|:------:|:-------------:|
| Adversarial AE | ✔ | ✔ | | | | | |
| Model distillation | ✔ | ✔ | ✔ | ✔ | ✔ | | |
### 漂移检测