
이상치, 적대적 및 드리프트 탐지 알고리즘
Alibi Detect는 이상치(outlier), 적대적(adversarial) 및 드리프트(drift) 탐지에 중점을 둔 소스 공개 Python 라이브러리입니다. 이 패키지는 테이블형 데이터, 텍스트, 이미지 및 시계열을 위한 온라인 및 오프라인 탐지기를 모두 지원하는 것을 목표로 합니다. 드리프트 탐지에는 TensorFlow 및 PyTorch 백엔드가 모두 지원됩니다.
프로덕션 환경에서 이상치와 분포를 모니터링하는 중요성에 대한 자세한 배경은 ICML 2020 워크숍 Challenges in Deploying and Monitoring Machine Learning Systems의 이 강연을 확인하세요. 이 강연은 논문 Monitoring and explainability of models in production을 기반으로 하며 Alibi Detect를 참조합니다.
드리프트 탐지에 대한 심층적인 소개는 Protecting Your Machine Learning Against Drift: An Introduction을 확인하세요. 이 강연에서는 드리프트가 무엇인지, 왜 탐지하는 것이 유익한지, 다양한 드리프트 유형, 원칙적인 방식으로 탐지하는 방법을 다루며 드리프트 탐지기의 구조(anatomy)도 설명합니다.
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
API를 설명하기 위해 VAE 이상치 탐지기를 사용하겠습니다.```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 | ✔ | ✔ | ✔ | ✔ | ✔ | | |
### 드리프트 탐지
| 탐지기 | 테이블 형식 | 이미지 | 시계열 | 텍스트 | 범주형 피처 | 온라인 | 피처 수준 |
|:---------------------------------| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| 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)
또는 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)
자세한 내용은 예제 노트북(예: [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), [Amazon 리뷰](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), [Amazon 리뷰](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
(X_train, y_train), (X_val, y_val), (X_test, y_test) = fetch_genome(return_X_y=True)
ECG 5000: fetch_ecg
NAB: fetch_nab
alibi_detect.datasets.get_list_nab()을 사용하여 검색할 수 있습니다.CIFAR-10-C: fetch_cifar10c
fetch_cifar10c를 사용하면 모든 심각도 수준이나 손상 유형을 선택할 수 있습니다. 사용 가능한 손상 유형 목록은 alibi_detect.datasets.corruption_types_cifar10c()로 검색할 수 있습니다. 이 데이터셋은 강건성 및 드리프트 연구에 사용할 수 있습니다. 원본 데이터는 여기에서 찾을 수 있습니다. 예: ```python
from alibi_detect.datasets import fetch_cifar10ccorruption = ['gaussian_noise', 'motion_blur', 'brightness', 'pixelate'] X, y = fetch_cifar10c(corruption=corruption, severity=5, return_X_y=True)
Adversarial CIFAR-10: fetch_attack
(X_train, y_train), (X_test, y_test) = fetch_attack('cifar10', 'resnet56', 'cw', return_X_y=True)
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
model = fetch_tf_model('cifar10', 'resnet32')
Alibi-detect는 머신러닝 모델 배포 플랫폼 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} }