Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
alibi-detect — 用于异常值、对抗性和漂移检测的算法 | Kitploit
工具/GitHubGitHub/seldonio/alibi-detect
机器学习AI 安全异常检测对抗性攻击
GitHubseldonio/alibi-detect

alibi-detect

用于异常值、对抗性和漂移检测的算法

查看仓库网站
2.5k2538个月前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

Alibi Detect 标志

Build Status Documentation Status codecov PyPI - Python Version PyPI - Package Version Conda (channel only) GitHub - License Slack channel


Alibi Detect 是一个源码可用的 Python 库,专注于异常值、对抗性和漂移检测。该包旨在覆盖适用于表格数据、文本、图像和时间序列的在线和离线检测器。漂移检测同时支持 TensorFlow 和 PyTorch 后端。

  • 文档

如需了解更多有关在生产环境中监测异常值和分布的重要性的背景信息,请查看来自 ICML 2020 研讨会 机器学习系统的部署与监测挑战 上的这个演讲,该演讲基于论文生产环境中模型的监测与可解释性并引用了 Alibi Detect。

如需全面了解漂移检测,请观看保护你的机器学习免受漂移影响:入门。该演讲涵盖了漂移是什么以及为什么值得检测、漂移的不同类型、如何以系统的方式检测漂移,并剖析了漂移检测器的内部构造。

目录

  • 安装与使用
    • 通过 pip
    • 通过 conda
    • 用法
  • 支持的算法
    • 异常检测
    • 对抗性检测
    • 漂移检测
      • TensorFlow 和 PyTorch 支持
      • 内置预处理步骤
    • 参考列表
      • 异常检测
      • 对抗性检测
      • 漂移检测
  • 数据集
    • 序列数据和时间序列
    • 图像
    • 表格数据
  • 模型
  • 集成
  • 引用

安装与使用

该包 alibi-detect 可以从以下位置安装:

  • PyPI 或 GitHub 源码(使用 pip)
  • Anaconda(使用 conda/mamba)

通过 pip

  • alibi-detect 可以从 PyPI 安装: ```bash pip install alibi-detect
    root@kitploit:~
  • 或者,可以安装开发版本: ```bash pip install git+https://github.com/SeldonIO/alibi-detect.git
    root@kitploit:~
  • 要使用 TensorFlow 后端安装: ```bash pip install alibi-detect[tensorflow]
    root@kitploit:~
  • 要使用 PyTorch 后端安装: ```bash pip install alibi-detect[torch]
    root@kitploit:~
  • 使用 KeOps 后端安装: ```bash pip install alibi-detect[keops]
    root@kitploit:~
  • 要使用 Prophet 时间序列异常值检测器: ```bash pip install alibi-detect[prophet]
    root@kitploit:~

使用 conda

要从 conda-forge 安装,建议使用 mamba, 可以通过以下命令将其安装到 base conda 环境中:```bash conda install mamba -n base -c conda-forge

root@kitploit:~
要安装 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

initialize and fit detector

od = OutlierVAE(threshold=0.1, encoder_net=encoder_net, decoder_net=decoder_net, latent_dim=1024) od.fit(x_train)

make predictions

preds = od.predict(x_test)

save and load detectors

filepath = './my_detector/' save_detector(od, filepath) od = load_detector(filepath)

root@kitploit:~
预测结果以字典形式返回,键为 `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 | ✔       | ✔     |      ✔      |  ✔   |          ✔           |        |               |

### 漂移检测

| 检测器 | 表格数据 | 图像 | 时间序列 | 文本 | 类别特征 | 在线 | 特征级别 |
|:---------------------------------|  :---:  | :---: |   :---:     | :---: |   :---:              | :---:  | :---:         |
| Kolmogorov-Smirnov               | ✔       | ✔     |             | ✔     | ✔                    |        | ✔             |
| Cramér-von Mises                 | ✔       | ✔     |             |       |                      | ✔      | ✔             |
| Fisher's Exact Test              | ✔       |       |             |       | ✔                    | ✔      | ✔             |
| Maximum Mean Discrepancy (MMD)   | ✔       | ✔     |             | ✔     | ✔                    | ✔      |               |
| Learned Kernel MMD               | ✔       | ✔     |             | ✔     | ✔                    |        |               |
| Context-aware MMD                | ✔       | ✔     |  ✔          | ✔     | ✔                    |        |               |
| Least-Squares Density Difference | ✔       | ✔     |             | ✔     | ✔                    | ✔      |               |
| Chi-Squared                      | ✔       |       |             |       | ✔                    |        | ✔             |
| Mixed-type tabular data          | ✔       |       |             |       | ✔                    |        | ✔             |
| Classifier                       | ✔       | ✔     |  ✔          | ✔     | ✔                    |        |               |
| Spot-the-diff                    | ✔       | ✔     |  ✔          | ✔     | ✔                    |        | ✔             |
| Classifier Uncertainty           | ✔       | ✔     |  ✔          | ✔     | ✔                    |        |               |
| Regressor Uncertainty            | ✔       | ✔     |  ✔          | ✔     | ✔                    |        |               |

#### TensorFlow 和 PyTorch 支持

漂移检测器支持 TensorFlow、PyTorch 以及(在适用的情况下)[KeOps](https://www.kernel-operations.io/keops/index.html) 后端。 
但是,Alibi Detect 默认不会安装这些。有关更多详细信息,请参阅[安装选项](#installation-and-usage)。```python
from alibi_detect.cd import MMDDrift

cd = MMDDrift(x_ref, backend='tensorflow', p_val=.05)
preds = cd.predict(x)

在 PyTorch 中的同一个检测器:```python cd = MMDDrift(x_ref, backend='pytorch', p_val=.05) preds = cd.predict(x)

root@kitploit:~
或者在 KeOps 中:```python
cd = MMDDrift(x_ref, backend='keops', p_val=.05)
preds = cd.predict(x)

内置预处理步骤

Alibi Detect 还提供了各种预处理步骤,例如随机初始化的编码器、预训练文本 嵌入,用于使用 transformers 库检测漂移,以及 从机器学习模型中提取隐藏层。这使得能够检测不同类型的漂移,例如 协变量偏移和预测分布偏移。这些预处理步骤同样在 TensorFlow 和 PyTorch 中得到支持。```python from alibi_detect.cd.tensorflow import HiddenOutput, preprocess_drift

model = # TensorFlow model; tf.keras.Model or tf.keras.Sequential preprocess_fn = partial(preprocess_drift, model=HiddenOutput(model, layer=-1), batch_size=128) cd = MMDDrift(x_ref, backend='tensorflow', p_val=.05, preprocess_fn=preprocess_fn) preds = cd.predict(x)

root@kitploit:~
请参阅示例笔记本(例如 [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mmd_cifar10.html)、[电影评论](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_imdb.html))以了解更多详情。

### 参考列表

#### 离群点检测

- [Isolation Forest](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/iforest.html) ([FT Liu et al., 2008](https://cs.nju.edu.cn/zhouzh/zhouzh.files/publication/icdm08b.pdf))
   - 示例:[网络入侵](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_if_kddcup.html)

- [Mahalanobis Distance](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/mahalanobis.html) ([Mahalanobis, 1936](https://insa.nic.in/writereaddata/UpLoadedFiles/PINSA/Vol02_1936_1_Art05.pdf))
   - 示例:[网络入侵](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_mahalanobis_kddcup.html)

- [Auto-Encoder (AE)](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/ae.html)
   - 示例:[CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_ae_cifar10.html)

- [Variational Auto-Encoder (VAE)](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/vae.html) ([Kingma et al., 2013](https://arxiv.org/abs/1312.6114))
   - 示例:[网络入侵](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_vae_kddcup.html)、[CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_vae_cifar10.html)

- [Auto-Encoding Gaussian Mixture Model (AEGMM)](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/aegmm.html) ([Zong et al., 2018](https://openreview.net/forum?id=BJJLHbb0-))
   - 示例:[网络入侵](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_aegmm_kddcup.html)

- [Variational Auto-Encoding Gaussian Mixture Model (VAEGMM)](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/vaegmm.html)
   - 示例:[网络入侵](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_aegmm_kddcup.html)
     
- [Likelihood Ratios](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/llr.html) ([Ren et al., 2019](https://arxiv.org/abs/1906.02845))
   - 示例:[基因组](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_llr_genome.html)、[Fashion-MNIST 对 MNIST](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_llr_mnist.html)

- [Prophet Time Series Outlier Detector](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/prophet.html) ([Taylor et al., 2018](https://peerj.com/preprints/3190/))
   - 示例:[天气预报](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_prophet_weather.html)
  
- [Spectral Residual Time Series Outlier Detector](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/sr.html) ([Ren et al., 2019](https://arxiv.org/abs/1906.03821))
   - 示例:[合成数据集](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_sr_synth.html)

- [Sequence-to-Sequence (Seq2Seq) Outlier Detector](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/seq2seq.html) ([Sutskever et al., 2014](https://papers.nips.cc/paper/5346-sequence-to-sequence-learning-with-neural-networks.pdf); [Park et al., 2017](https://arxiv.org/pdf/1711.00614.pdf))
   - 示例:[ECG](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_seq2seq_ecg.html)、[合成数据集](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_seq2seq_synth.html)
  
#### 对抗检测

- [Adversarial Auto-Encoder](https://docs.seldon.io/projects/alibi-detect/en/stable/ad/methods/adversarialae.html) ([Vacanti and Van Looveren, 2020](https://arxiv.org/abs/2002.09364))
   - 示例:[CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/ad_ae_cifar10.html)

- [Model distillation](https://docs.seldon.io/projects/alibi-detect/en/stable/ad/methods/modeldistillation.html) 
   - 示例:[CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_distillation_cifar10.html)
     
#### 漂移检测

- [Kolmogorov-Smirnov](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/ksdrift.html)
   - 示例:[CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_ks_cifar10.html)、[分子图](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mol.html)、[电影评论](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_imdb.html)

- [Cramér-von Mises](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/cvmdrift.html)
  - 示例:[企鹅](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_supervised_penguins.html)

- [Fisher's Exact Test](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/fetdrift.html)
  - 示例:[企鹅](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_supervised_penguins.html)

- [Least-Squares Density Difference](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/lsdddrift.html) ([Bu et al, 2016](https://alippi.faculty.polimi.it/articoli/A%20Pdf%20free%20Change%20Detection%20Test%20Based%20on%20Density%20Difference%20Estimation.pdf))

- [Maximum Mean Discrepancy](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/mmddrift.html) ([Gretton et al, 2012](http://jmlr.csail.mit.edu/papers/v13/gretton12a.html))
   - 示例:[CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mmd_cifar10.html)、[分子图](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mol.html)、[电影评论](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_imdb.html)、[亚马逊评论](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_amazon.html)

- [Learned Kernel MMD](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/learnedkerneldrift.html) ([Liu et al, 2020](https://arxiv.org/abs/2002.09116))
  - 示例:[CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_clf_cifar10.html)

- [Context-aware MMD](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/contextmmddrift.html) ([Cobb and Van Looveren, 2022](https://arxiv.org/abs/2203.08644))
  - 示例:[ECG](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_context_ecg.html)、[新闻主题](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_context_20newsgroup.html)

- [Chi-Squared](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/chisquaredrift.html)
   - 示例:[收入预测](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_chi2ks_adult.html)

- [Mixed-type tabular data](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/tabulardrift.html)
   - 示例:[收入预测](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_chi2ks_adult.html)

- [Classifier](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/classifierdrift.html) ([Lopez-Paz and Oquab, 2017](https://openreview.net/forum?id=SJkXfE5xx))
   - 示例:[CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_clf_cifar10.html)、[亚马逊评论](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_amazon.html)

- [Spot-the-diff](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/spotthediffdrift.html) (adaptation of [Jitkrittum et al, 2016](https://arxiv.org/abs/1605.06796))
  - 示例 [MNIST 与葡萄酒质量](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/spot_the_diff_mnist_win.html)

- [Classifier and Regressor Uncertainty](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/modeluncdrift.html)
   - 示例:[CIFAR10 与葡萄酒](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_model_unc_cifar10_wine.html)、[分子图](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mol.html)

- [Online Maximum Mean Discrepancy](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/onlinemmddrift.html)
  - 示例:[葡萄酒质量](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_online_wine.html)、[Camelyon 医学影像](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_online_camelyon.html)
  
- [Online Least-Squares Density Difference](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/onlinemmddrift.html) ([Bu et al, 2017](https://ieeexplore.ieee.org/abstract/document/7890493))
  - 示例:[葡萄酒质量](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_online_wine.html)

## 数据集

该软件包还在 `alibi_detect.datasets` 中提供了相应功能,可轻松获取不同模态的多个数据集。对于每个数据集,返回数据与标签,或返回包含数据、标签和可选元数据的 *Bunch* 对象。示例:```python
from alibi_detect.datasets import fetch_ecg

(X_train, y_train), (X_test, y_test) = fetch_ecg(return_X_y=True)

序列数据与时间序列

  • 基因组数据集:fetch_genome

    • 用于分布外检测的细菌基因组数据集,作为 用于分布外检测的似然比 的一部分发布。根据原始 TL;DR:该数据集包含来自 10 个分布内细菌类别的 250 个碱基对的基因组序列用于训练,60 个 OOD 细菌类别用于验证,以及另外 60 个不同的 OOD 细菌类别用于测试。训练集、验证集和测试集分别包含 100 万、700 万和 700 万条序列。有关数据集的详细信息,请查看 README。 ```python from alibi_detect.datasets import fetch_genome

    (X_train, y_train), (X_val, y_val), (X_test, y_test) = fetch_genome(return_X_y=True)

    root@kitploit:~
  • ECG 5000: fetch_ecg

    • 5000 个 ECG 数据,最初从 Physionet 获取。
  • NAB: fetch_nab

    • 来自 Numenta Anomaly Benchmark 的 DataFrame 中的任意单变量时间序列。可以使用 alibi_detect.datasets.get_list_nab() 获取可用时间序列的列表。

图像

  • CIFAR-10-C: fetch_cifar10c

    • CIFAR-10-C (Hendrycks & Dietterich, 2019) 包含 CIFAR-10 的测试集,但以不同的严重程度被各种类型的噪声、模糊、亮度等破坏和扰动,导致在 CIFAR-10 上训练的分类模型性能逐渐下降。fetch_cifar10c 允许你选择任意严重程度或损坏类型。可用的损坏类型列表可以通过 alibi_detect.datasets.corruption_types_cifar10c() 获取。该数据集可用于鲁棒性和漂移方面的研究。原始数据可以在这里找到。示例: ```python from alibi_detect.datasets import fetch_cifar10c

    corruption = ['gaussian_noise', 'motion_blur', 'brightness', 'pixelate'] X, y = fetch_cifar10c(corruption=corruption, severity=5, return_X_y=True)

    root@kitploit:~
  • 对抗性 CIFAR-10: fetch_attack

    • 在基于 CIFAR-10 训练的 ResNet-56 分类器上加载对抗性实例。可用攻击:Carlini-Wagner ('cw') 和 SLIDE ('slide')。示例: ```python from alibi_detect.datasets import fetch_attack

    (X_train, y_train), (X_test, y_test) = fetch_attack('cifar10', 'resnet56', 'cw', return_X_y=True)

    root@kitploit:~

表格数据

  • KDD Cup '99: fetch_kdd
    • 包含不同类型的计算机网络入侵的数据集。fetch_kdd 允许您选择网络入侵的一个子集作为目标,或仅挑选指定的特征。原始数据可在此处找到。

模型

在 alibi_detect.models 下可以找到在离群点、对抗性或漂移检测之外也可能有用的模型和/或构建模块。主要实现:

  • PixelCNN++: alibi_detect.models.pixelcnn.PixelCNN

  • 变分自编码器:alibi_detect.models.autoencoder.VAE

  • 序列到序列模型:alibi_detect.models.autoencoder.Seq2Seq

  • ResNet:alibi_detect.models.resnet

    • 在 CIFAR-10 上预训练的 ResNet-20/32/44 模型可以在我们的 Google Cloud Bucket 上找到,并可按如下方式获取: ```python from alibi_detect.utils.fetching import fetch_tf_model

    model = fetch_tf_model('cifar10', 'resnet32')

    root@kitploit:~

集成

Alibi-detect 已集成到机器学习模型部署平台 Seldon Core 和模型服务框架 KFServing 中。

  • Seldon Core:离群点 和 漂移 检测示例。

  • KFServing:离群点 和 漂移 检测示例。

引用

如果您在研究中使用 alibi-detect,请考虑引用它。

BibTeX 条目:``` @software{alibi-detect, title = {Alibi Detect: Algorithms for outlier, adversarial and drift detection}, author = {Van Looveren, Arnaud and Klaise, Janis and Vacanti, Giovanni and Cobb, Oliver and Scillitoe, Ashley and Samoilescu, Robert and Athorne, Alex}, url = {https://github.com/SeldonIO/alibi-detect}, version = {0.13.0}, date = {2025-12-11}, year = {2019} }

root@kitploit:~
下载工具