summaryrefslogtreecommitdiff
path: root/python-alibi-detect.spec
blob: 84c729fd1c554a70e769ea3fa743f0ed95cf75f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
%global _empty_manifest_terminate_build 0
Name:		python-alibi-detect
Version:	0.11.1
Release:	1
Summary:	Algorithms for outlier detection, concept drift and metrics.
License:	Apache 2.0
URL:		https://github.com/SeldonIO/alibi-detect
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/f8/b3/7f4cfb302b8f3aa605bdb63b28fe3b0e59825461e05af00061c595859457/alibi-detect-0.11.1.tar.gz
BuildArch:	noarch

Requires:	python3-matplotlib
Requires:	python3-numpy
Requires:	python3-pandas
Requires:	python3-Pillow
Requires:	python3-opencv-python
Requires:	python3-scipy
Requires:	python3-scikit-image
Requires:	python3-scikit-learn
Requires:	python3-transformers
Requires:	python3-dill
Requires:	python3-tqdm
Requires:	python3-requests
Requires:	python3-pydantic
Requires:	python3-toml
Requires:	python3-catalogue
Requires:	python3-numba
Requires:	python3-typing-extensions
Requires:	python3-prophet
Requires:	python3-tensorflow-probability
Requires:	python3-tensorflow
Requires:	python3-pykeops
Requires:	python3-torch
Requires:	python3-pykeops
Requires:	python3-torch
Requires:	python3-prophet
Requires:	python3-tensorflow-probability
Requires:	python3-tensorflow
Requires:	python3-torch

%description
[Alibi Detect](https://github.com/SeldonIO/alibi-detect) is an open source Python library focused on **outlier**, **adversarial** and **drift** detection. The package aims to cover both online and offline detectors for tabular data, text, images and time series. Both **TensorFlow** and **PyTorch** backends are supported for drift detection.
*  [Documentation](https://docs.seldon.io/projects/alibi-detect/en/stable/)
For more background on the importance of monitoring outliers and distributions in a production setting, check out [this talk](https://slideslive.com/38931758/monitoring-and-explainability-of-models-in-production?ref=speaker-37384-latest) from the *Challenges in Deploying and Monitoring Machine Learning Systems* ICML 2020 workshop, based on the paper [Monitoring and explainability of models in production](https://arxiv.org/abs/2007.06299) and referencing Alibi Detect.
For a thorough introduction to drift detection, check out [Protecting Your Machine Learning Against Drift: An Introduction](https://youtu.be/tL5sEaQha5o). The talk covers what drift is and why it pays to detect it, the different types of drift, how it can be detected in a principled manner and also describes the anatomy of a drift detector.
## Table of Contents
- [Installation and Usage](#installation-and-usage)
  - [With pip](#with-pip)
  - [With conda](#with-conda)
  - [Usage](#usage)   
- [Supported Algorithms](#supported-algorithms)
  - [Outlier Detection](#outlier-detection)
  - [Adversarial Detection](#adversarial-detection)
  - [Drift Detection](#drift-detection)
    - [TensorFlow and PyTorch support](#tensorflow-and-pytorch-support)
    - [Built-in preprocessing steps](#built-in-preprocessing-steps)
  - [Reference List](#reference-list)
    - [Outlier Detection](#outlier-detection-1)
    - [Adversarial Detection](#adversarial-detection-1)
    - [Drift Detection](#drift-detection-1)
- [Datasets](#datasets)
  - [Sequential Data and Time Series](#sequential-data-and-time-series)
  - [Images](#images)
  - [Tabular](#tabular)
- [Models](#models)
- [Integrations](#integrations)
- [Citations](#citations)
## Installation and Usage
The package, `alibi-detect` can be installed from:
- PyPI or GitHub source (with `pip`)
- Anaconda (with `conda`/`mamba`)
### With pip
- alibi-detect can be installed from [PyPI](https://pypi.org/project/alibi-detect):
   ```bash
   pip install alibi-detect
   ```
- Alternatively, the development version can be installed:
   ```bash
   pip install git+https://github.com/SeldonIO/alibi-detect.git
   ```
- To install with the TensorFlow backend:
  ```bash
  pip install alibi-detect[tensorflow]
  ```
- To install with the PyTorch backend:
  ```bash
  pip install alibi-detect[torch]
  ```
- To install with the KeOps backend:
  ```bash
  pip install alibi-detect[keops]
  ```
- To use the `Prophet` time series outlier detector:
   ```bash
   pip install alibi-detect[prophet]
   ```
### With conda
To install from [conda-forge](https://conda-forge.org/) it is recommended to use [mamba](https://mamba.readthedocs.io/en/stable/), 
which can be installed to the *base* conda enviroment with:
```bash
conda install mamba -n base -c conda-forge
```
To install alibi-detect:
```bash
mamba install -c conda-forge alibi-detect
```
### Usage
We will use the [VAE outlier detector](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/vae.html) to illustrate the 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)
```
The predictions are returned in a dictionary with as keys `meta` and `data`. `meta` contains the detector's metadata while `data` is in itself a dictionary with the actual predictions. It contains the outlier, adversarial or drift scores and thresholds as well as the predictions whether instances are e.g. outliers or not. The exact details can vary slightly from method to method, so we encourage the reader to become familiar with the [types of algorithms supported](https://docs.seldon.io/projects/alibi-detect/en/stable/overview/algorithms.html).
## Supported Algorithms
The following tables show the advised use cases for each algorithm. The column *Feature Level* indicates whether the detection can be done at the feature level, e.g. per pixel for an image. Check the [algorithm reference list](#reference-list) for more information with links to the documentation and original papers as well as examples for each of the detectors.
### Outlier Detection
| Detector             | Tabular | Image | Time Series | Text | Categorical Features | Online | Feature Level |
|:---------------------|:-------:|:-----:|:-----------:|:----:|:--------------------:|:------:|:-------------:|
| Isolation Forest     |    ✔    |       |             |      |          ✔           |        |               |
| Mahalanobis Distance |    ✔    |       |             |      |          ✔           |   ✔    |               |
| AE                   |    ✔    |   ✔   |             |      |                      |        |       ✔       |
| VAE                  |    ✔    |   ✔   |             |      |                      |        |       ✔       |
| AEGMM                |    ✔    |   ✔   |             |      |                      |        |               |
| VAEGMM               |    ✔    |   ✔   |             |      |                      |        |               |
| Likelihood Ratios    |    ✔    |   ✔   |      ✔      |      |          ✔           |        |       ✔       |
| Prophet              |         |       |      ✔      |      |                      |        |               |
| Spectral Residual    |         |       |      ✔      |      |                      |   ✔    |       ✔       |
| Seq2Seq              |         |       |      ✔      |      |                      |        |       ✔       |
### Adversarial Detection
| Detector           | Tabular | Image | Time Series | Text | Categorical Features | Online | Feature Level |
| :---               |  :---:  | :---: |:-----------:|:----:|:--------------------:|:------:|:-------------:|
| Adversarial AE     | ✔       | ✔     |             |      |                      |        |               |
| Model distillation | ✔       | ✔     |      ✔      |  ✔   |          ✔           |        |               |
### Drift Detection
| Detector                         | Tabular | Image | Time Series | Text  | Categorical Features | Online | Feature Level |
|:---------------------------------|  :---:  | :---: |   :---:     | :---: |   :---:              | :---:  | :---:         |
| 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 and PyTorch support
The drift detectors support TensorFlow, PyTorch and (where applicable) [KeOps](https://www.kernel-operations.io/keops/index.html) backends. 
However, Alibi Detect does not install these by default. See the [installation options](#installation-and-usage) for more details.
```python
from alibi_detect.cd import MMDDrift
cd = MMDDrift(x_ref, backend='tensorflow', p_val=.05)
preds = cd.predict(x)
```
The same detector in PyTorch:
```python
cd = MMDDrift(x_ref, backend='pytorch', p_val=.05)
preds = cd.predict(x)
```
Or in KeOps:
```python
cd = MMDDrift(x_ref, backend='keops', p_val=.05)
preds = cd.predict(x)
```
#### Built-in preprocessing steps
Alibi Detect also comes with various preprocessing steps such as randomly initialized encoders, pretrained text
embeddings to detect drift on using the [transformers](https://github.com/huggingface/transformers) library and 
extraction of hidden layers from machine learning models. This allows to detect different types of drift such as 
**covariate and predicted distribution shift**. The preprocessing steps are again supported in TensorFlow and 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)
```
Check the example notebooks (e.g. [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mmd_cifar10.html), [movie reviews](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_imdb.html)) for more details.
### Reference List
#### Outlier Detection
- [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))
   - Example: [Network Intrusion](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))
   - Example: [Network Intrusion](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)
   - Example: [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))
   - Examples: [Network Intrusion](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-))
   - Example: [Network Intrusion](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)
   - Example: [Network Intrusion](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))
   - Examples: [Genome](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_llr_genome.html), [Fashion-MNIST vs. 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/))
   - Example: [Weather Forecast](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))
   - Example: [Synthetic Dataset](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))
   - Examples: [ECG](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_seq2seq_ecg.html), [Synthetic Dataset](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_seq2seq_synth.html)
#### Adversarial Detection
- [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))
   - Example: [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) 
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_distillation_cifar10.html)
#### Drift Detection
- [Kolmogorov-Smirnov](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/ksdrift.html)
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_ks_cifar10.html), [molecular graphs](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mol.html), [movie reviews](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)
  - Example: [Penguins](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)
  - Example: [Penguins](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))
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mmd_cifar10.html), [molecular graphs](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mol.html), [movie reviews](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_imdb.html), [Amazon reviews](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))
  - Example: [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))
  - Example: [ECG](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_context_ecg.html), [news topics](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)
   - Example: [Income Prediction](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)
   - Example: [Income Prediction](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))
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_clf_cifar10.html), [Amazon reviews](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))
  - Example [MNIST and Wine quality](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)
   - Example: [CIFAR10 and Wine](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_model_unc_cifar10_wine.html), [molecular graphs](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)
  - Example: [Wine Quality](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_online_wine.html), [Camelyon medical imaging](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))
  - Example: [Wine Quality](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_online_wine.html)
## Datasets
The package also contains functionality in `alibi_detect.datasets` to easily fetch a number of datasets for different modalities. For each dataset either the data and labels or a *Bunch* object with the data, labels and optional metadata are returned. Example:
```python
from alibi_detect.datasets import fetch_ecg
(X_train, y_train), (X_test, y_test) = fetch_ecg(return_X_y=True)
```
### Sequential Data and Time Series
- **Genome Dataset**: `fetch_genome`
  - Bacteria genomics dataset for out-of-distribution detection, released as part of [Likelihood Ratios for Out-of-Distribution Detection](https://arxiv.org/abs/1906.02845). From the original *TL;DR*: *The dataset contains genomic sequences of 250 base pairs from 10 in-distribution bacteria classes for training, 60 OOD bacteria classes for validation, and another 60 different OOD bacteria classes for test*. There are respectively 1, 7 and again 7 million sequences in the training, validation and test sets. For detailed info on the dataset check the [README](https://storage.cloud.google.com/seldon-datasets/genome/readme.docx?organizationId=156002945562).
  ```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)
  ```
- **ECG 5000**: `fetch_ecg`
  - 5000 ECG's, originally obtained from [Physionet](https://archive.physionet.org/cgi-bin/atm/ATM).
- **NAB**: `fetch_nab`
  - Any univariate time series in a DataFrame from the [Numenta Anomaly Benchmark](https://github.com/numenta/NAB). A list with the available time series can be retrieved using `alibi_detect.datasets.get_list_nab()`.
### Images
- **CIFAR-10-C**: `fetch_cifar10c`
  - CIFAR-10-C ([Hendrycks & Dietterich, 2019](https://arxiv.org/abs/1903.12261)) contains the test set of CIFAR-10, but corrupted and perturbed by various types of noise, blur, brightness etc. at different levels of severity, leading to a gradual decline in a classification model's performance trained on CIFAR-10. `fetch_cifar10c` allows you to pick any severity level or corruption type. The list with available corruption types can be retrieved with `alibi_detect.datasets.corruption_types_cifar10c()`. The dataset can be used in research on robustness and drift. The original data can be found [here](https://zenodo.org/record/2535967#.XnAM2nX7RNw). Example:
  ```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)
  ```
- **Adversarial CIFAR-10**: `fetch_attack`
  - Load adversarial instances on a ResNet-56 classifier trained on CIFAR-10. Available attacks: [Carlini-Wagner](https://arxiv.org/abs/1608.04644) ('cw') and [SLIDE](https://arxiv.org/abs/1904.13000) ('slide'). Example:
  ```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)
  ```
### Tabular
- **KDD Cup '99**: `fetch_kdd`
  - Dataset with different types of computer network intrusions. `fetch_kdd` allows you to select a subset of network intrusions as targets or pick only specified features. The original data can be found [here](http://kdd.ics.uci.edu/databases/kddcup99/kddcup99.html).
## Models
Models and/or building blocks that can be useful outside of outlier, adversarial or drift detection can be found under `alibi_detect.models`. Main implementations:
- [PixelCNN++](https://arxiv.org/abs/1701.05517): `alibi_detect.models.pixelcnn.PixelCNN`
- Variational Autoencoder: `alibi_detect.models.autoencoder.VAE`
- Sequence-to-sequence model: `alibi_detect.models.autoencoder.Seq2Seq`
- ResNet: `alibi_detect.models.resnet`
  - Pre-trained ResNet-20/32/44 models on CIFAR-10 can be found on our [Google Cloud Bucket](https://console.cloud.google.com/storage/browser/seldon-models/alibi-detect/classifier/cifar10/?organizationId=156002945562&project=seldon-pub) and can be fetched as follows:
  ```python
  from alibi_detect.utils.fetching import fetch_tf_model
  model = fetch_tf_model('cifar10', 'resnet32')
  ```
## Integrations
Alibi-detect is integrated in the open source machine learning model deployment platform [Seldon Core](https://docs.seldon.io/projects/seldon-core/en/stable/index.html) and model serving framework [KFServing](https://github.com/kubeflow/kfserving).
- **Seldon Core**: [outlier](https://docs.seldon.io/projects/seldon-core/en/stable/analytics/outlier_detection.html) and [drift](https://docs.seldon.io/projects/seldon-core/en/stable/analytics/drift_detection.html) detection worked examples.
- **KFServing**: [outlier](https://github.com/kubeflow/kfserving/tree/master/docs/samples/outlier-detection/alibi-detect/cifar10) and [drift](https://github.com/kubeflow/kfserving/tree/master/docs/samples/drift-detection/alibi-detect/cifar10) detection examples.
## Citations
If you use alibi-detect in your research, please consider citing it.
BibTeX entry:
```
@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.11.1},
  date = {2023-03-03},
  year = {2019}
}
```

%package -n python3-alibi-detect
Summary:	Algorithms for outlier detection, concept drift and metrics.
Provides:	python-alibi-detect
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-alibi-detect
[Alibi Detect](https://github.com/SeldonIO/alibi-detect) is an open source Python library focused on **outlier**, **adversarial** and **drift** detection. The package aims to cover both online and offline detectors for tabular data, text, images and time series. Both **TensorFlow** and **PyTorch** backends are supported for drift detection.
*  [Documentation](https://docs.seldon.io/projects/alibi-detect/en/stable/)
For more background on the importance of monitoring outliers and distributions in a production setting, check out [this talk](https://slideslive.com/38931758/monitoring-and-explainability-of-models-in-production?ref=speaker-37384-latest) from the *Challenges in Deploying and Monitoring Machine Learning Systems* ICML 2020 workshop, based on the paper [Monitoring and explainability of models in production](https://arxiv.org/abs/2007.06299) and referencing Alibi Detect.
For a thorough introduction to drift detection, check out [Protecting Your Machine Learning Against Drift: An Introduction](https://youtu.be/tL5sEaQha5o). The talk covers what drift is and why it pays to detect it, the different types of drift, how it can be detected in a principled manner and also describes the anatomy of a drift detector.
## Table of Contents
- [Installation and Usage](#installation-and-usage)
  - [With pip](#with-pip)
  - [With conda](#with-conda)
  - [Usage](#usage)   
- [Supported Algorithms](#supported-algorithms)
  - [Outlier Detection](#outlier-detection)
  - [Adversarial Detection](#adversarial-detection)
  - [Drift Detection](#drift-detection)
    - [TensorFlow and PyTorch support](#tensorflow-and-pytorch-support)
    - [Built-in preprocessing steps](#built-in-preprocessing-steps)
  - [Reference List](#reference-list)
    - [Outlier Detection](#outlier-detection-1)
    - [Adversarial Detection](#adversarial-detection-1)
    - [Drift Detection](#drift-detection-1)
- [Datasets](#datasets)
  - [Sequential Data and Time Series](#sequential-data-and-time-series)
  - [Images](#images)
  - [Tabular](#tabular)
- [Models](#models)
- [Integrations](#integrations)
- [Citations](#citations)
## Installation and Usage
The package, `alibi-detect` can be installed from:
- PyPI or GitHub source (with `pip`)
- Anaconda (with `conda`/`mamba`)
### With pip
- alibi-detect can be installed from [PyPI](https://pypi.org/project/alibi-detect):
   ```bash
   pip install alibi-detect
   ```
- Alternatively, the development version can be installed:
   ```bash
   pip install git+https://github.com/SeldonIO/alibi-detect.git
   ```
- To install with the TensorFlow backend:
  ```bash
  pip install alibi-detect[tensorflow]
  ```
- To install with the PyTorch backend:
  ```bash
  pip install alibi-detect[torch]
  ```
- To install with the KeOps backend:
  ```bash
  pip install alibi-detect[keops]
  ```
- To use the `Prophet` time series outlier detector:
   ```bash
   pip install alibi-detect[prophet]
   ```
### With conda
To install from [conda-forge](https://conda-forge.org/) it is recommended to use [mamba](https://mamba.readthedocs.io/en/stable/), 
which can be installed to the *base* conda enviroment with:
```bash
conda install mamba -n base -c conda-forge
```
To install alibi-detect:
```bash
mamba install -c conda-forge alibi-detect
```
### Usage
We will use the [VAE outlier detector](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/vae.html) to illustrate the 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)
```
The predictions are returned in a dictionary with as keys `meta` and `data`. `meta` contains the detector's metadata while `data` is in itself a dictionary with the actual predictions. It contains the outlier, adversarial or drift scores and thresholds as well as the predictions whether instances are e.g. outliers or not. The exact details can vary slightly from method to method, so we encourage the reader to become familiar with the [types of algorithms supported](https://docs.seldon.io/projects/alibi-detect/en/stable/overview/algorithms.html).
## Supported Algorithms
The following tables show the advised use cases for each algorithm. The column *Feature Level* indicates whether the detection can be done at the feature level, e.g. per pixel for an image. Check the [algorithm reference list](#reference-list) for more information with links to the documentation and original papers as well as examples for each of the detectors.
### Outlier Detection
| Detector             | Tabular | Image | Time Series | Text | Categorical Features | Online | Feature Level |
|:---------------------|:-------:|:-----:|:-----------:|:----:|:--------------------:|:------:|:-------------:|
| Isolation Forest     |    ✔    |       |             |      |          ✔           |        |               |
| Mahalanobis Distance |    ✔    |       |             |      |          ✔           |   ✔    |               |
| AE                   |    ✔    |   ✔   |             |      |                      |        |       ✔       |
| VAE                  |    ✔    |   ✔   |             |      |                      |        |       ✔       |
| AEGMM                |    ✔    |   ✔   |             |      |                      |        |               |
| VAEGMM               |    ✔    |   ✔   |             |      |                      |        |               |
| Likelihood Ratios    |    ✔    |   ✔   |      ✔      |      |          ✔           |        |       ✔       |
| Prophet              |         |       |      ✔      |      |                      |        |               |
| Spectral Residual    |         |       |      ✔      |      |                      |   ✔    |       ✔       |
| Seq2Seq              |         |       |      ✔      |      |                      |        |       ✔       |
### Adversarial Detection
| Detector           | Tabular | Image | Time Series | Text | Categorical Features | Online | Feature Level |
| :---               |  :---:  | :---: |:-----------:|:----:|:--------------------:|:------:|:-------------:|
| Adversarial AE     | ✔       | ✔     |             |      |                      |        |               |
| Model distillation | ✔       | ✔     |      ✔      |  ✔   |          ✔           |        |               |
### Drift Detection
| Detector                         | Tabular | Image | Time Series | Text  | Categorical Features | Online | Feature Level |
|:---------------------------------|  :---:  | :---: |   :---:     | :---: |   :---:              | :---:  | :---:         |
| 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 and PyTorch support
The drift detectors support TensorFlow, PyTorch and (where applicable) [KeOps](https://www.kernel-operations.io/keops/index.html) backends. 
However, Alibi Detect does not install these by default. See the [installation options](#installation-and-usage) for more details.
```python
from alibi_detect.cd import MMDDrift
cd = MMDDrift(x_ref, backend='tensorflow', p_val=.05)
preds = cd.predict(x)
```
The same detector in PyTorch:
```python
cd = MMDDrift(x_ref, backend='pytorch', p_val=.05)
preds = cd.predict(x)
```
Or in KeOps:
```python
cd = MMDDrift(x_ref, backend='keops', p_val=.05)
preds = cd.predict(x)
```
#### Built-in preprocessing steps
Alibi Detect also comes with various preprocessing steps such as randomly initialized encoders, pretrained text
embeddings to detect drift on using the [transformers](https://github.com/huggingface/transformers) library and 
extraction of hidden layers from machine learning models. This allows to detect different types of drift such as 
**covariate and predicted distribution shift**. The preprocessing steps are again supported in TensorFlow and 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)
```
Check the example notebooks (e.g. [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mmd_cifar10.html), [movie reviews](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_imdb.html)) for more details.
### Reference List
#### Outlier Detection
- [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))
   - Example: [Network Intrusion](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))
   - Example: [Network Intrusion](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)
   - Example: [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))
   - Examples: [Network Intrusion](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-))
   - Example: [Network Intrusion](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)
   - Example: [Network Intrusion](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))
   - Examples: [Genome](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_llr_genome.html), [Fashion-MNIST vs. 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/))
   - Example: [Weather Forecast](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))
   - Example: [Synthetic Dataset](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))
   - Examples: [ECG](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_seq2seq_ecg.html), [Synthetic Dataset](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_seq2seq_synth.html)
#### Adversarial Detection
- [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))
   - Example: [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) 
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_distillation_cifar10.html)
#### Drift Detection
- [Kolmogorov-Smirnov](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/ksdrift.html)
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_ks_cifar10.html), [molecular graphs](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mol.html), [movie reviews](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)
  - Example: [Penguins](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)
  - Example: [Penguins](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))
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mmd_cifar10.html), [molecular graphs](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mol.html), [movie reviews](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_imdb.html), [Amazon reviews](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))
  - Example: [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))
  - Example: [ECG](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_context_ecg.html), [news topics](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)
   - Example: [Income Prediction](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)
   - Example: [Income Prediction](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))
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_clf_cifar10.html), [Amazon reviews](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))
  - Example [MNIST and Wine quality](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)
   - Example: [CIFAR10 and Wine](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_model_unc_cifar10_wine.html), [molecular graphs](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)
  - Example: [Wine Quality](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_online_wine.html), [Camelyon medical imaging](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))
  - Example: [Wine Quality](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_online_wine.html)
## Datasets
The package also contains functionality in `alibi_detect.datasets` to easily fetch a number of datasets for different modalities. For each dataset either the data and labels or a *Bunch* object with the data, labels and optional metadata are returned. Example:
```python
from alibi_detect.datasets import fetch_ecg
(X_train, y_train), (X_test, y_test) = fetch_ecg(return_X_y=True)
```
### Sequential Data and Time Series
- **Genome Dataset**: `fetch_genome`
  - Bacteria genomics dataset for out-of-distribution detection, released as part of [Likelihood Ratios for Out-of-Distribution Detection](https://arxiv.org/abs/1906.02845). From the original *TL;DR*: *The dataset contains genomic sequences of 250 base pairs from 10 in-distribution bacteria classes for training, 60 OOD bacteria classes for validation, and another 60 different OOD bacteria classes for test*. There are respectively 1, 7 and again 7 million sequences in the training, validation and test sets. For detailed info on the dataset check the [README](https://storage.cloud.google.com/seldon-datasets/genome/readme.docx?organizationId=156002945562).
  ```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)
  ```
- **ECG 5000**: `fetch_ecg`
  - 5000 ECG's, originally obtained from [Physionet](https://archive.physionet.org/cgi-bin/atm/ATM).
- **NAB**: `fetch_nab`
  - Any univariate time series in a DataFrame from the [Numenta Anomaly Benchmark](https://github.com/numenta/NAB). A list with the available time series can be retrieved using `alibi_detect.datasets.get_list_nab()`.
### Images
- **CIFAR-10-C**: `fetch_cifar10c`
  - CIFAR-10-C ([Hendrycks & Dietterich, 2019](https://arxiv.org/abs/1903.12261)) contains the test set of CIFAR-10, but corrupted and perturbed by various types of noise, blur, brightness etc. at different levels of severity, leading to a gradual decline in a classification model's performance trained on CIFAR-10. `fetch_cifar10c` allows you to pick any severity level or corruption type. The list with available corruption types can be retrieved with `alibi_detect.datasets.corruption_types_cifar10c()`. The dataset can be used in research on robustness and drift. The original data can be found [here](https://zenodo.org/record/2535967#.XnAM2nX7RNw). Example:
  ```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)
  ```
- **Adversarial CIFAR-10**: `fetch_attack`
  - Load adversarial instances on a ResNet-56 classifier trained on CIFAR-10. Available attacks: [Carlini-Wagner](https://arxiv.org/abs/1608.04644) ('cw') and [SLIDE](https://arxiv.org/abs/1904.13000) ('slide'). Example:
  ```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)
  ```
### Tabular
- **KDD Cup '99**: `fetch_kdd`
  - Dataset with different types of computer network intrusions. `fetch_kdd` allows you to select a subset of network intrusions as targets or pick only specified features. The original data can be found [here](http://kdd.ics.uci.edu/databases/kddcup99/kddcup99.html).
## Models
Models and/or building blocks that can be useful outside of outlier, adversarial or drift detection can be found under `alibi_detect.models`. Main implementations:
- [PixelCNN++](https://arxiv.org/abs/1701.05517): `alibi_detect.models.pixelcnn.PixelCNN`
- Variational Autoencoder: `alibi_detect.models.autoencoder.VAE`
- Sequence-to-sequence model: `alibi_detect.models.autoencoder.Seq2Seq`
- ResNet: `alibi_detect.models.resnet`
  - Pre-trained ResNet-20/32/44 models on CIFAR-10 can be found on our [Google Cloud Bucket](https://console.cloud.google.com/storage/browser/seldon-models/alibi-detect/classifier/cifar10/?organizationId=156002945562&project=seldon-pub) and can be fetched as follows:
  ```python
  from alibi_detect.utils.fetching import fetch_tf_model
  model = fetch_tf_model('cifar10', 'resnet32')
  ```
## Integrations
Alibi-detect is integrated in the open source machine learning model deployment platform [Seldon Core](https://docs.seldon.io/projects/seldon-core/en/stable/index.html) and model serving framework [KFServing](https://github.com/kubeflow/kfserving).
- **Seldon Core**: [outlier](https://docs.seldon.io/projects/seldon-core/en/stable/analytics/outlier_detection.html) and [drift](https://docs.seldon.io/projects/seldon-core/en/stable/analytics/drift_detection.html) detection worked examples.
- **KFServing**: [outlier](https://github.com/kubeflow/kfserving/tree/master/docs/samples/outlier-detection/alibi-detect/cifar10) and [drift](https://github.com/kubeflow/kfserving/tree/master/docs/samples/drift-detection/alibi-detect/cifar10) detection examples.
## Citations
If you use alibi-detect in your research, please consider citing it.
BibTeX entry:
```
@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.11.1},
  date = {2023-03-03},
  year = {2019}
}
```

%package help
Summary:	Development documents and examples for alibi-detect
Provides:	python3-alibi-detect-doc
%description help
[Alibi Detect](https://github.com/SeldonIO/alibi-detect) is an open source Python library focused on **outlier**, **adversarial** and **drift** detection. The package aims to cover both online and offline detectors for tabular data, text, images and time series. Both **TensorFlow** and **PyTorch** backends are supported for drift detection.
*  [Documentation](https://docs.seldon.io/projects/alibi-detect/en/stable/)
For more background on the importance of monitoring outliers and distributions in a production setting, check out [this talk](https://slideslive.com/38931758/monitoring-and-explainability-of-models-in-production?ref=speaker-37384-latest) from the *Challenges in Deploying and Monitoring Machine Learning Systems* ICML 2020 workshop, based on the paper [Monitoring and explainability of models in production](https://arxiv.org/abs/2007.06299) and referencing Alibi Detect.
For a thorough introduction to drift detection, check out [Protecting Your Machine Learning Against Drift: An Introduction](https://youtu.be/tL5sEaQha5o). The talk covers what drift is and why it pays to detect it, the different types of drift, how it can be detected in a principled manner and also describes the anatomy of a drift detector.
## Table of Contents
- [Installation and Usage](#installation-and-usage)
  - [With pip](#with-pip)
  - [With conda](#with-conda)
  - [Usage](#usage)   
- [Supported Algorithms](#supported-algorithms)
  - [Outlier Detection](#outlier-detection)
  - [Adversarial Detection](#adversarial-detection)
  - [Drift Detection](#drift-detection)
    - [TensorFlow and PyTorch support](#tensorflow-and-pytorch-support)
    - [Built-in preprocessing steps](#built-in-preprocessing-steps)
  - [Reference List](#reference-list)
    - [Outlier Detection](#outlier-detection-1)
    - [Adversarial Detection](#adversarial-detection-1)
    - [Drift Detection](#drift-detection-1)
- [Datasets](#datasets)
  - [Sequential Data and Time Series](#sequential-data-and-time-series)
  - [Images](#images)
  - [Tabular](#tabular)
- [Models](#models)
- [Integrations](#integrations)
- [Citations](#citations)
## Installation and Usage
The package, `alibi-detect` can be installed from:
- PyPI or GitHub source (with `pip`)
- Anaconda (with `conda`/`mamba`)
### With pip
- alibi-detect can be installed from [PyPI](https://pypi.org/project/alibi-detect):
   ```bash
   pip install alibi-detect
   ```
- Alternatively, the development version can be installed:
   ```bash
   pip install git+https://github.com/SeldonIO/alibi-detect.git
   ```
- To install with the TensorFlow backend:
  ```bash
  pip install alibi-detect[tensorflow]
  ```
- To install with the PyTorch backend:
  ```bash
  pip install alibi-detect[torch]
  ```
- To install with the KeOps backend:
  ```bash
  pip install alibi-detect[keops]
  ```
- To use the `Prophet` time series outlier detector:
   ```bash
   pip install alibi-detect[prophet]
   ```
### With conda
To install from [conda-forge](https://conda-forge.org/) it is recommended to use [mamba](https://mamba.readthedocs.io/en/stable/), 
which can be installed to the *base* conda enviroment with:
```bash
conda install mamba -n base -c conda-forge
```
To install alibi-detect:
```bash
mamba install -c conda-forge alibi-detect
```
### Usage
We will use the [VAE outlier detector](https://docs.seldon.io/projects/alibi-detect/en/stable/od/methods/vae.html) to illustrate the 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)
```
The predictions are returned in a dictionary with as keys `meta` and `data`. `meta` contains the detector's metadata while `data` is in itself a dictionary with the actual predictions. It contains the outlier, adversarial or drift scores and thresholds as well as the predictions whether instances are e.g. outliers or not. The exact details can vary slightly from method to method, so we encourage the reader to become familiar with the [types of algorithms supported](https://docs.seldon.io/projects/alibi-detect/en/stable/overview/algorithms.html).
## Supported Algorithms
The following tables show the advised use cases for each algorithm. The column *Feature Level* indicates whether the detection can be done at the feature level, e.g. per pixel for an image. Check the [algorithm reference list](#reference-list) for more information with links to the documentation and original papers as well as examples for each of the detectors.
### Outlier Detection
| Detector             | Tabular | Image | Time Series | Text | Categorical Features | Online | Feature Level |
|:---------------------|:-------:|:-----:|:-----------:|:----:|:--------------------:|:------:|:-------------:|
| Isolation Forest     |    ✔    |       |             |      |          ✔           |        |               |
| Mahalanobis Distance |    ✔    |       |             |      |          ✔           |   ✔    |               |
| AE                   |    ✔    |   ✔   |             |      |                      |        |       ✔       |
| VAE                  |    ✔    |   ✔   |             |      |                      |        |       ✔       |
| AEGMM                |    ✔    |   ✔   |             |      |                      |        |               |
| VAEGMM               |    ✔    |   ✔   |             |      |                      |        |               |
| Likelihood Ratios    |    ✔    |   ✔   |      ✔      |      |          ✔           |        |       ✔       |
| Prophet              |         |       |      ✔      |      |                      |        |               |
| Spectral Residual    |         |       |      ✔      |      |                      |   ✔    |       ✔       |
| Seq2Seq              |         |       |      ✔      |      |                      |        |       ✔       |
### Adversarial Detection
| Detector           | Tabular | Image | Time Series | Text | Categorical Features | Online | Feature Level |
| :---               |  :---:  | :---: |:-----------:|:----:|:--------------------:|:------:|:-------------:|
| Adversarial AE     | ✔       | ✔     |             |      |                      |        |               |
| Model distillation | ✔       | ✔     |      ✔      |  ✔   |          ✔           |        |               |
### Drift Detection
| Detector                         | Tabular | Image | Time Series | Text  | Categorical Features | Online | Feature Level |
|:---------------------------------|  :---:  | :---: |   :---:     | :---: |   :---:              | :---:  | :---:         |
| 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 and PyTorch support
The drift detectors support TensorFlow, PyTorch and (where applicable) [KeOps](https://www.kernel-operations.io/keops/index.html) backends. 
However, Alibi Detect does not install these by default. See the [installation options](#installation-and-usage) for more details.
```python
from alibi_detect.cd import MMDDrift
cd = MMDDrift(x_ref, backend='tensorflow', p_val=.05)
preds = cd.predict(x)
```
The same detector in PyTorch:
```python
cd = MMDDrift(x_ref, backend='pytorch', p_val=.05)
preds = cd.predict(x)
```
Or in KeOps:
```python
cd = MMDDrift(x_ref, backend='keops', p_val=.05)
preds = cd.predict(x)
```
#### Built-in preprocessing steps
Alibi Detect also comes with various preprocessing steps such as randomly initialized encoders, pretrained text
embeddings to detect drift on using the [transformers](https://github.com/huggingface/transformers) library and 
extraction of hidden layers from machine learning models. This allows to detect different types of drift such as 
**covariate and predicted distribution shift**. The preprocessing steps are again supported in TensorFlow and 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)
```
Check the example notebooks (e.g. [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mmd_cifar10.html), [movie reviews](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_imdb.html)) for more details.
### Reference List
#### Outlier Detection
- [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))
   - Example: [Network Intrusion](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))
   - Example: [Network Intrusion](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)
   - Example: [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))
   - Examples: [Network Intrusion](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-))
   - Example: [Network Intrusion](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)
   - Example: [Network Intrusion](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))
   - Examples: [Genome](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_llr_genome.html), [Fashion-MNIST vs. 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/))
   - Example: [Weather Forecast](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))
   - Example: [Synthetic Dataset](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))
   - Examples: [ECG](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_seq2seq_ecg.html), [Synthetic Dataset](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/od_seq2seq_synth.html)
#### Adversarial Detection
- [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))
   - Example: [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) 
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_distillation_cifar10.html)
#### Drift Detection
- [Kolmogorov-Smirnov](https://docs.seldon.io/projects/alibi-detect/en/stable/cd/methods/ksdrift.html)
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_ks_cifar10.html), [molecular graphs](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mol.html), [movie reviews](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)
  - Example: [Penguins](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)
  - Example: [Penguins](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))
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mmd_cifar10.html), [molecular graphs](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_mol.html), [movie reviews](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_text_imdb.html), [Amazon reviews](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))
  - Example: [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))
  - Example: [ECG](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_context_ecg.html), [news topics](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)
   - Example: [Income Prediction](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)
   - Example: [Income Prediction](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))
   - Example: [CIFAR10](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_clf_cifar10.html), [Amazon reviews](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))
  - Example [MNIST and Wine quality](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)
   - Example: [CIFAR10 and Wine](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_model_unc_cifar10_wine.html), [molecular graphs](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)
  - Example: [Wine Quality](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_online_wine.html), [Camelyon medical imaging](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))
  - Example: [Wine Quality](https://docs.seldon.io/projects/alibi-detect/en/stable/examples/cd_online_wine.html)
## Datasets
The package also contains functionality in `alibi_detect.datasets` to easily fetch a number of datasets for different modalities. For each dataset either the data and labels or a *Bunch* object with the data, labels and optional metadata are returned. Example:
```python
from alibi_detect.datasets import fetch_ecg
(X_train, y_train), (X_test, y_test) = fetch_ecg(return_X_y=True)
```
### Sequential Data and Time Series
- **Genome Dataset**: `fetch_genome`
  - Bacteria genomics dataset for out-of-distribution detection, released as part of [Likelihood Ratios for Out-of-Distribution Detection](https://arxiv.org/abs/1906.02845). From the original *TL;DR*: *The dataset contains genomic sequences of 250 base pairs from 10 in-distribution bacteria classes for training, 60 OOD bacteria classes for validation, and another 60 different OOD bacteria classes for test*. There are respectively 1, 7 and again 7 million sequences in the training, validation and test sets. For detailed info on the dataset check the [README](https://storage.cloud.google.com/seldon-datasets/genome/readme.docx?organizationId=156002945562).
  ```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)
  ```
- **ECG 5000**: `fetch_ecg`
  - 5000 ECG's, originally obtained from [Physionet](https://archive.physionet.org/cgi-bin/atm/ATM).
- **NAB**: `fetch_nab`
  - Any univariate time series in a DataFrame from the [Numenta Anomaly Benchmark](https://github.com/numenta/NAB). A list with the available time series can be retrieved using `alibi_detect.datasets.get_list_nab()`.
### Images
- **CIFAR-10-C**: `fetch_cifar10c`
  - CIFAR-10-C ([Hendrycks & Dietterich, 2019](https://arxiv.org/abs/1903.12261)) contains the test set of CIFAR-10, but corrupted and perturbed by various types of noise, blur, brightness etc. at different levels of severity, leading to a gradual decline in a classification model's performance trained on CIFAR-10. `fetch_cifar10c` allows you to pick any severity level or corruption type. The list with available corruption types can be retrieved with `alibi_detect.datasets.corruption_types_cifar10c()`. The dataset can be used in research on robustness and drift. The original data can be found [here](https://zenodo.org/record/2535967#.XnAM2nX7RNw). Example:
  ```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)
  ```
- **Adversarial CIFAR-10**: `fetch_attack`
  - Load adversarial instances on a ResNet-56 classifier trained on CIFAR-10. Available attacks: [Carlini-Wagner](https://arxiv.org/abs/1608.04644) ('cw') and [SLIDE](https://arxiv.org/abs/1904.13000) ('slide'). Example:
  ```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)
  ```
### Tabular
- **KDD Cup '99**: `fetch_kdd`
  - Dataset with different types of computer network intrusions. `fetch_kdd` allows you to select a subset of network intrusions as targets or pick only specified features. The original data can be found [here](http://kdd.ics.uci.edu/databases/kddcup99/kddcup99.html).
## Models
Models and/or building blocks that can be useful outside of outlier, adversarial or drift detection can be found under `alibi_detect.models`. Main implementations:
- [PixelCNN++](https://arxiv.org/abs/1701.05517): `alibi_detect.models.pixelcnn.PixelCNN`
- Variational Autoencoder: `alibi_detect.models.autoencoder.VAE`
- Sequence-to-sequence model: `alibi_detect.models.autoencoder.Seq2Seq`
- ResNet: `alibi_detect.models.resnet`
  - Pre-trained ResNet-20/32/44 models on CIFAR-10 can be found on our [Google Cloud Bucket](https://console.cloud.google.com/storage/browser/seldon-models/alibi-detect/classifier/cifar10/?organizationId=156002945562&project=seldon-pub) and can be fetched as follows:
  ```python
  from alibi_detect.utils.fetching import fetch_tf_model
  model = fetch_tf_model('cifar10', 'resnet32')
  ```
## Integrations
Alibi-detect is integrated in the open source machine learning model deployment platform [Seldon Core](https://docs.seldon.io/projects/seldon-core/en/stable/index.html) and model serving framework [KFServing](https://github.com/kubeflow/kfserving).
- **Seldon Core**: [outlier](https://docs.seldon.io/projects/seldon-core/en/stable/analytics/outlier_detection.html) and [drift](https://docs.seldon.io/projects/seldon-core/en/stable/analytics/drift_detection.html) detection worked examples.
- **KFServing**: [outlier](https://github.com/kubeflow/kfserving/tree/master/docs/samples/outlier-detection/alibi-detect/cifar10) and [drift](https://github.com/kubeflow/kfserving/tree/master/docs/samples/drift-detection/alibi-detect/cifar10) detection examples.
## Citations
If you use alibi-detect in your research, please consider citing it.
BibTeX entry:
```
@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.11.1},
  date = {2023-03-03},
  year = {2019}
}
```

%prep
%autosetup -n alibi-detect-0.11.1

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-alibi-detect -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Tue Apr 25 2023 Python_Bot <Python_Bot@openeuler.org> - 0.11.1-1
- Package Spec generated