mishig HF Staff commited on
Commit
b6d5a11
·
verified ·
1 Parent(s): 08d3a77

Add 1 files

Browse files
Files changed (1) hide show
  1. 2009/2009.02572.md +167 -0
2009/2009.02572.md ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Title: PySAD: A Streaming Anomaly Detection Framework in Python
2
+
3
+ URL Source: https://arxiv.org/html/2009.02572
4
+
5
+ Markdown Content:
6
+ \name Selim F. Yilmaz \email s.yilmaz21@imperial.ac.uk
7
+
8
+ \addr Department of Electrical and Electronic Engineering
9
+
10
+ Imperial College London
11
+
12
+ London, United Kingdom \AND\name Suleyman S. Kozat \email kozat@ee.bilkent.edu.tr
13
+
14
+ \addr Department of Electrical and Electronic Engineering
15
+
16
+ Bilkent University
17
+
18
+ Ankara, Turkey
19
+
20
+ ###### Abstract
21
+
22
+ Streaming anomaly detection requires algorithms that operate under strict constraints: bounded memory, single-pass processing, and constant-time complexity. We present PySAD, a comprehensive Python framework addressing these challenges through a unified architecture. The framework implements 17+ streaming algorithms (LODA, Half-Space Trees, xStream) with specialized components including projectors, probability calibrators, and postprocessors. Unlike existing batch-focused frameworks, PySAD enables efficient real-time processing with bounded memory while maintaining compatibility with PyOD and scikit-learn. Supporting all learning paradigms for univariate and multivariate streams, PySAD provides the most comprehensive streaming anomaly detection toolkit in Python. The source code is publicly available at [github.com/selimfirat/pysad](https://github.com/selimfirat/pysad).
23
+
24
+ Keywords: Anomaly detection, streaming data, online learning, Python, real-time analytics.
25
+
26
+ 1 Introduction
27
+ --------------
28
+
29
+ Anomaly detection on streaming data has become critical in real-time analytics, driven by applications in cybersecurity(Yuan et al., [2014](https://arxiv.org/html/2009.02572v2#bib.bib27)), network intrusion(Kloft and Laskov, [2010](https://arxiv.org/html/2009.02572v2#bib.bib10)), and face presentation attack detection(Yilmaz and Kozat, [2020a](https://arxiv.org/html/2009.02572v2#bib.bib25)). Modern data streams require algorithms that can process data points in real-time while adapting to evolving patterns and concept drift(Gama et al., [2014](https://arxiv.org/html/2009.02572v2#bib.bib4)).
30
+
31
+ Streaming anomaly detection imposes stringent constraints: single-pass processing, bounded memory usage, constant-time processing, and adaptive learning. These constraints eliminate global optimization possibilities and require fundamentally different algorithmic approaches(Henzinger et al., [1998](https://arxiv.org/html/2009.02572v2#bib.bib7)).
32
+
33
+ Existing frameworks reveal significant gaps: scikit-learn(Pedregosa et al., [2011](https://arxiv.org/html/2009.02572v2#bib.bib16)) focuses on batch processing, River(Montiel et al., [2021](https://arxiv.org/html/2009.02572v2#bib.bib15)) provides limited anomaly detection, and PyOD(Zhao et al., [2019](https://arxiv.org/html/2009.02572v2#bib.bib28)) lacks streaming optimizations. This fragmentation necessitates a dedicated streaming-focused framework.
34
+
35
+ We introduce PySAD, a comprehensive Python framework for streaming anomaly detection. The framework provides 17+ algorithms, from classical approaches (LODA(Pevný, [2016](https://arxiv.org/html/2009.02572v2#bib.bib17)), Half-Space Trees(Tan et al., [2011](https://arxiv.org/html/2009.02572v2#bib.bib20))) to modern ensemble methods (xStream(Manzoor et al., [2018](https://arxiv.org/html/2009.02572v2#bib.bib13)), sequential ensemble learning(Yilmaz and Kozat, [2020b](https://arxiv.org/html/2009.02572v2#bib.bib26))), supporting univariate and multivariate streams across supervised, semi-supervised, and unsupervised paradigms(Yılmaz, [2021](https://arxiv.org/html/2009.02572v2#bib.bib24)).
36
+
37
+ Beyond core algorithms, PySAD provides a complete ecosystem: stream simulators, evaluation metrics, adaptive preprocessors, statistical trackers, probability calibrators, postprocessors, and batch-to-streaming integration utilities. The framework emphasizes production readiness through rigorous engineering practices and performance optimizations ensuring sub-millisecond processing.
38
+
39
+ 2 Streaming Anomaly Detection and PySAD
40
+ ---------------------------------------
41
+
42
+ ![Image 1: Refer to caption](https://arxiv.org/html/2009.02572v2/x1.png)
43
+
44
+ Figure 1: The usage of components in PySAD as a pipeline.
45
+
46
+ A streaming anomaly detection model ℳ ℳ\mathcal{M}caligraphic_M receives a potentially infinite stream 𝒟={(𝒙 t,y t)∣t=1,2,…}𝒟 conditional-set subscript 𝒙 𝑡 subscript 𝑦 𝑡 𝑡 1 2…\mathcal{D}=\{(\mbox{\boldmath${x}$}_{t},y_{t})\mid t=1,2,...\}caligraphic_D = { ( bold_italic_x start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT , italic_y start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT ) ∣ italic_t = 1 , 2 , … }, where 𝒙 t∈ℝ m subscript 𝒙 𝑡 superscript ℝ 𝑚\mbox{\boldmath${x}$}_{t}\in\mathbb{R}^{m}bold_italic_x start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT ∈ blackboard_R start_POSTSUPERSCRIPT italic_m end_POSTSUPERSCRIPT is a feature vector and y t subscript 𝑦 𝑡 y_{t}italic_y start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT is the binary anomaly label:
47
+
48
+ y t={1,if 𝒙 t⁢is anomalous,0,otherwise.subscript 𝑦 𝑡 cases 1 subscript if 𝒙 𝑡 is anomalous,0 otherwise.\displaystyle y_{t}=\begin{cases}1,&\text{ if }\mbox{\boldmath${x}$}_{t}\text{% is anomalous,}\\ 0,&\text{ otherwise.}\end{cases}italic_y start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT = { start_ROW start_CELL 1 , end_CELL start_CELL if roman_x start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT is anomalous, end_CELL end_ROW start_ROW start_CELL 0 , end_CELL start_CELL otherwise. end_CELL end_ROW
49
+
50
+ Streaming anomaly detection operates under three fundamental constraints: single-pass processing (each instance observed once), bounded memory (constant or sublinear growth), and constant-time processing (bounded per-instance complexity). These constraints eliminate traditional optimization approaches and necessitate online learning algorithms(Gama et al., [2014](https://arxiv.org/html/2009.02572v2#bib.bib4)).
51
+
52
+ All models in PySAD extend the BaseModel class providing:
53
+
54
+ * •fit_partial(𝒙 t,y t subscript 𝒙 𝑡 subscript 𝑦 𝑡\mbox{\boldmath${x}$}_{t},\,y_{t}bold_italic_x start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT , italic_y start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT): Incrementally trains using instance (𝒙 t,y t)subscript 𝒙 𝑡 subscript 𝑦 𝑡(\mbox{\boldmath${x}$}_{t},y_{t})( bold_italic_x start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT , italic_y start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT )
55
+ * •score_partial(𝒙 t subscript 𝒙 𝑡\mbox{\boldmath${x}$}_{t}bold_italic_x start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT): Returns anomaly score for 𝒙 t subscript 𝒙 𝑡\mbox{\boldmath${x}$}_{t}bold_italic_x start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT
56
+ * •fit_score_partial(𝒙 t,y t subscript 𝒙 𝑡 subscript 𝑦 𝑡\mbox{\boldmath${x}$}_{t},y_{t}bold_italic_x start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT , italic_y start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT): Combines training and scoring
57
+
58
+ Figure[1](https://arxiv.org/html/2009.02572v2#S2.F1 "Figure 1 ‣ 2 Streaming Anomaly Detection and PySAD ‣ PySAD: A Streaming Anomaly Detection Framework in Python") illustrates PySAD’s modular architecture:
59
+
60
+ Preprocessors transform input data for normalization and scaling in streaming scenarios. Projectors map data to lower-dimensional spaces for efficiency. Models form the core detection component with classical (LODA, Half-Space Trees) and ensemble methods (xStream). Ensemblers combine multiple model outputs and can be used to combine data points (early fusion) or decisions (late fusion)(Mandıra et al., [2019](https://arxiv.org/html/2009.02572v2#bib.bib12); Giritlioğlu et al., [2021](https://arxiv.org/html/2009.02572v2#bib.bib5); Yilmaz and Kozat, [2020b](https://arxiv.org/html/2009.02572v2#bib.bib26)). Postprocessors refine scores through temporal smoothing and adaptive thresholding. Probability Calibrators convert scores into interpretable probabilities using Gaussian tail fitting(Ahmad et al., [2017](https://arxiv.org/html/2009.02572v2#bib.bib1)) or conformal prediction(Ishimtsev et al., [2017](https://arxiv.org/html/2009.02572v2#bib.bib9)). One can add models by extending BaseModel and implementing fit_partial and score_partial. Details are available at [pysad.readthedocs.io](https://pysad.readthedocs.io/).
61
+
62
+ ### 2.1 Usage Example
63
+
64
+ The following example demonstrates typical PySAD usage for streaming anomaly detection:
65
+
66
+ from pysad.evaluation.metrics import AUROCMetric
67
+
68
+ from pysad.models.loda import LODA
69
+
70
+ from pysad.utils.data import Data
71
+
72
+ model=LODA()
73
+
74
+ metric=AUROCMetric()
75
+
76
+ streaming_data=Data().get_iterator("arrhythmia.mat")
77
+
78
+ for x,y_true in streaming_data:
79
+
80
+ anomaly_score=model.fit_score_partial(x)
81
+
82
+ metric.update(y_true,anomaly_score)
83
+
84
+ print(f"Area under ROC metric is{metric.get()}.")
85
+
86
+ This example showcases the framework’s simplicity: initialization requires minimal configuration, streaming data processing follows the standard fit_score_partial pattern, and evaluation metrics are updated incrementally.
87
+
88
+ 3 Comparison with Related Software
89
+ ----------------------------------
90
+
91
+ Existing streaming anomaly detection frameworks can be categorized into (i) general streaming machine learning frameworks and (ii) batch-oriented anomaly detection libraries.
92
+
93
+ Streaming Frameworks:River(Montiel et al., [2021](https://arxiv.org/html/2009.02572v2#bib.bib15)) and skmultiflow(Montiel et al., [2018](https://arxiv.org/html/2009.02572v2#bib.bib14)) implement only Half-Space Trees(Tan et al., [2011](https://arxiv.org/html/2009.02572v2#bib.bib20)) for streaming anomaly detection. CapyMOA(Gomes et al., [2025](https://arxiv.org/html/2009.02572v2#bib.bib6)) provides 3 models through Python interfaces to MOA’s Java algorithms(Bifet et al., [2010](https://arxiv.org/html/2009.02572v2#bib.bib2)). Jubat.us(Hido et al., [2013](https://arxiv.org/html/2009.02572v2#bib.bib8)) implements only Local Outlier Factor(Breunig et al., [2000](https://arxiv.org/html/2009.02572v2#bib.bib3)) in C++. Alibi-detect offers limited streaming methods(Ren et al., [2019](https://arxiv.org/html/2009.02572v2#bib.bib18); Le and Ho, [2005](https://arxiv.org/html/2009.02572v2#bib.bib11)).
94
+
95
+ Batch Frameworks:PyOD(Zhao et al., [2019](https://arxiv.org/html/2009.02572v2#bib.bib28)) and ADTK(Wen, [2020](https://arxiv.org/html/2009.02572v2#bib.bib23)) excel in offline scenarios but lack streaming capabilities and do not address concept drift, memory constraints, or real-time processing requirements.
96
+
97
+ PySAD’s Position:PySAD is purpose-built for streaming anomaly detection with 17+ specialized algorithms and uniquely provides unsupervised probability calibrators for converting raw scores into interpretable probabilities(Safin and Burnaev, [2017](https://arxiv.org/html/2009.02572v2#bib.bib19)).
98
+
99
+ Table[1](https://arxiv.org/html/2009.02572v2#S3.T1 "Table 1 ‣ 3 Comparison with Related Software ‣ PySAD: A Streaming Anomaly Detection Framework in Python") presents a comprehensive comparison highlighting PySAD’s distinctive focus on streaming anomaly detection and its comprehensive toolkit for building end-to-end streaming pipelines.
100
+
101
+ * *The number of specialized algorithms for streaming anomaly detection.
102
+ * •Current versions: river (0.22.0), jubat.us (1.1.1), adtk (0.6.2), pyod (2.0.5), skmultiflow (0.5.3), alibi-detect (0.12.0), moa (24.07.0), capymoa (0.9.1), pysad (0.3.0).
103
+
104
+ Table 1: Comparison with existing frameworks for streaming anomaly detection.
105
+
106
+ As a specialized streaming anomaly detection framework, PySAD complements existing streaming frameworks and batch-oriented anomaly detection libraries while addressing the unique challenges of real-time anomaly detection.
107
+
108
+ 4 Development and Architecture
109
+ ------------------------------
110
+
111
+ PySAD is architected as a production-ready framework emphasizing scalability, maintainability, and performance. The framework is distributed under the BSD 3-Clause License for broad compatibility.
112
+
113
+ ### 4.1 Software Engineering Practices
114
+
115
+ Our development methodology emphasizes quality assurance and collaborative development:
116
+
117
+ * •Collaborative Development: Hosted on GitHub with issue tracking, pull request workflows, and active community contributions.
118
+ * •Quality Assurance: 95%+ code coverage, continuous integration across multiple platforms, PEP8 compliance, and comprehensive API documentation.
119
+ * •Performance Optimization: Memory-efficient NumPy vectorization, constant-time algorithms, and sub-millisecond processing for high-throughput streams.
120
+ * •Minimal Dependencies: Core dependencies include NumPy(Van Der Walt et al., [2011](https://arxiv.org/html/2009.02572v2#bib.bib21)), scikit-learn(Pedregosa et al., [2011](https://arxiv.org/html/2009.02572v2#bib.bib16)), SciPy(Virtanen et al., [2020](https://arxiv.org/html/2009.02572v2#bib.bib22)), and selective PyOD(Zhao et al., [2019](https://arxiv.org/html/2009.02572v2#bib.bib28)) integration.
121
+
122
+ ### 4.2 Architectural Design
123
+
124
+ The framework implements modular architecture based on the Strategy pattern:
125
+
126
+ * •Interface Consistency: Standardized interfaces (BaseModel, BaseTransform, BaseMetric) ensure seamless interoperability.
127
+ * •Memory Safety: Automatic memory management with configurable bounds and leak prevention.
128
+ * •Extensibility: Plugin architecture for easy algorithm contributions with minimal interface implementation.
129
+ * •Production Readiness: Thread-safe implementations, comprehensive logging, and graceful error handling.
130
+
131
+ PySAD supports Python 3.10+ and installs via PyPI (pip install pysad) with automatic dependency resolution.
132
+
133
+ Acknowledgments
134
+
135
+ This work is supported by the Turkish Academy of Sciences Outstanding Researcher Programme and Tubitak Contract No: 117E153. We thank all contributors and the open-source community for their valuable feedback and contributions.
136
+
137
+ References
138
+ ----------
139
+
140
+ * Ahmad et al. (2017) S.Ahmad, A.Lavin, S.Purdy, and Z.Agha. Unsupervised real-time anomaly detection for streaming data. _Neurocomputing_, 262:134–147, 2017.
141
+ * Bifet et al. (2010) A.Bifet, G.Holmes, B.Pfahringer, P.Kranen, H.Kremer, T.Jansen, and T.Seidl. Moa: Massive online analysis, a framework for stream classification and clustering. In _Proceedings of the First Workshop on Applications of Pattern Analysis_, pages 44–50, 2010.
142
+ * Breunig et al. (2000) M.M. Breunig, H.-P. Kriegel, R.T. Ng, and J.Sander. Lof: Identifying density-based local outliers. In _Proceedings of the 2000 ACM SIGMOD International Conference on Management of Data_, pages 93–104, 2000.
143
+ * Gama et al. (2014) J.Gama, I.Žliobaitė, A.Bifet, M.Pechenizkiy, and A.Bouchachia. A survey on concept drift adaptation. _ACM computing surveys_, 46(4):1–37, 2014.
144
+ * Giritlioğlu et al. (2021) D.Giritlioğlu, B.Mandira, S.F. Yilmaz, C.U. Ertenli, B.F. Akgür, M.Kınıklıoğlu, A.G. Kurt, E.Mutlu, Ş.C. Gürel, and H.Dibeklioğlu. Multimodal analysis of personality traits on videos of self-presentation and induced behavior. _Journal on Multimodal User Interfaces_, 15(4):337–358, 2021.
145
+ * Gomes et al. (2025) H.M. Gomes, A.Lee, N.Gunasekara, Y.Sun, G.W. Cassales, J.J. Liu, M.Heyden, V.Cerqueira, M.Bahri, Y.S. Koh, B.Pfahringer, and A.Bifet. CapyMOA: Efficient machine learning for data streams in python, 2025. URL [https://arxiv.org/abs/2502.07432](https://arxiv.org/abs/2502.07432).
146
+ * Henzinger et al. (1998) M.R. Henzinger, P.Raghavan, and S.Rajagopalan. Computing on data streams. _External Memory Algorithms_, 50:107–118, 1998.
147
+ * Hido et al. (2013) S.Hido, S.Tokui, and S.Oda. Jubatus: An open source platform for distributed online machine learning. In _NIPS 2013 Workshop on Big Learning, Lake Tahoe_, 2013.
148
+ * Ishimtsev et al. (2017) V.Ishimtsev, A.Bernstein, E.Burnaev, and I.Nazarov. Conformal k 𝑘 k italic_k-nn anomaly detector for univariate data streams. In _Conformal and Probabilistic Prediction and Applications_, pages 213–227, 2017.
149
+ * Kloft and Laskov (2010) M.Kloft and P.Laskov. Online anomaly detection under adversarial impact. In _Proceedings of the Thirteenth International Conference on Artificial Intelligence and Statistics_, pages 405–412, 2010.
150
+ * Le and Ho (2005) S.Q. Le and T.B. Ho. An association-based dissimilarity measure for categorical data. _Pattern Recognition Letters_, 26(16):2549–2557, 2005.
151
+ * Mandıra et al. (2019) B.Mandıra, D.Giritlioglu, S.F. Yilmaz, C.U. Ertenli, B.F. Akgür, M.Kınıklıoğlu, A.G. Kurt, M.N. Doganlı, E.Mutlu, S.C. Gürel, et al. Spatiotemporal and multimodal analysis of personality traits. In _15th International Summer Workshop on Multimodal Interfaces_, page 32, 2019.
152
+ * Manzoor et al. (2018) E.Manzoor, H.Lamba, and L.Akoglu. xstream: Outlier detection in feature-evolving data streams. In _Proceedings of the 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining_, pages 1963–1972, 2018.
153
+ * Montiel et al. (2018) J.Montiel, J.Read, A.Bifet, and T.Abdessalem. Scikit-multiflow: A multi-output streaming framework. _Journal of Machine Learning Research_, 19(1):2915–2914, 2018.
154
+ * Montiel et al. (2021) J.Montiel, M.Halford, S.M. Mastelini, G.Bolmier, R.Sourty, R.Vaysse, A.Zouitine, H.M. Gomes, J.Read, T.Abdessalem, et al. River: machine learning for streaming data in python. _Journal of Machine Learning Research_, 22(110):1–8, 2021.
155
+ * Pedregosa et al. (2011) F.Pedregosa, G.Varoquaux, A.Gramfort, V.Michel, B.Thirion, O.Grisel, M.Blondel, P.Prettenhofer, R.Weiss, V.Dubourg, et al. Scikit-learn: Machine learning in python. _Journal of machine learning research_, 12:2825–2830, 2011.
156
+ * Pevný (2016) T.Pevný. Loda: Lightweight on-line detector of anomalies. _Machine Learning_, 102(2):275–304, 2016.
157
+ * Ren et al. (2019) H.Ren, B.Xu, Y.Wang, C.Yi, C.Huang, X.Kou, T.Xing, M.Yang, J.Tong, and Q.Zhang. Time-series anomaly detection service at microsoft. In _Proceedings of the 25th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining_, pages 3009–3017, 2019.
158
+ * Safin and Burnaev (2017) A.M. Safin and E.Burnaev. Conformal kernel expected similarity for anomaly detection in time-series data. _Advances in Systems Science and Applications_, 17(3):22–33, 2017.
159
+ * Tan et al. (2011) S.C. Tan, K.M. Ting, and T.F. Liu. Fast anomaly detection for streaming data. In _Twenty-Second International Joint Conference on Artificial Intelligence_, 2011.
160
+ * Van Der Walt et al. (2011) S.Van Der Walt, S.C. Colbert, and G.Varoquaux. The NumPy array: a structure for efficient numerical computation. _Computing in science & engineering_, 13(2):22–30, 2011.
161
+ * Virtanen et al. (2020) P.Virtanen, R.Gommers, T.E. Oliphant, M.Haberland, T.Reddy, D.Cournapeau, E.Burovski, P.Peterson, W.Weckesser, J.Bright, et al. SciPy 1.0: fundamental algorithms for scientific computing in Python. _Nature methods_, 17(3):261–272, 2020.
162
+ * Wen (2020) T.Wen. Adtk: Anomaly detection toolkit, 2020. URL [https://github.com/arundo/adtk](https://github.com/arundo/adtk).
163
+ * Yılmaz (2021) S.F. Yılmaz. Unsupervised anomaly detection via deep metric learning with end-to-end optimization. Master’s thesis, Bilkent University (Türkiye), 2021.
164
+ * Yilmaz and Kozat (2020a) S.F. Yilmaz and S.S. Kozat. Face presentation attack detection via spatiotemporal autoencoder. In _IEEE Signal Processing and Communications Applications Conference_, 2020a.
165
+ * Yilmaz and Kozat (2020b) S.F. Yilmaz and S.S. Kozat. Robust anomaly detection via sequential ensemble learning. In _IEEE Signal Processing and Communications Applications Conference_, 2020b.
166
+ * Yuan et al. (2014) Y.Yuan, J.Fang, and Q.Wang. Online anomaly detection in crowd scenes via structure analysis. _IEEE Transactions on Cybernetics_, 45(3):548–561, 2014.
167
+ * Zhao et al. (2019) Y.Zhao, Zain Nasrullah, and Zheng Li. Pyod: A python toolbox for scalable outlier detection. _Journal of Machine Learning Research_, 20(96):1–7, 2019.