{"id":13418347,"url":"https://github.com/yzhao062/pyod","last_synced_at":"2026-05-11T09:37:50.323Z","repository":{"id":37612155,"uuid":"105699750","full_name":"yzhao062/pyod","owner":"yzhao062","description":"A Python Library for Outlier and Anomaly Detection, Integrating Classical and Deep Learning Techniques","archived":false,"fork":false,"pushed_at":"2025-04-29T22:31:24.000Z","size":41232,"stargazers_count":9185,"open_issues_count":232,"forks_count":1414,"subscribers_count":148,"default_branch":"master","last_synced_at":"2025-05-12T13:05:43.032Z","etag":null,"topics":["anomaly","anomaly-detection","autoencoder","data-analysis","data-mining","data-science","deep-learning","fraud-detection","machine-learning","neural-networks","novelty-detection","out-of-distribution-detection","outlier-detection","outlier-ensembles","outliers","python","python3","unsupervised-learning"],"latest_commit_sha":null,"homepage":"http://pyod.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yzhao062.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["yzhao062"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-10-03T20:29:04.000Z","updated_at":"2025-05-11T08:20:05.000Z","dependencies_parsed_at":"2023-02-12T09:16:06.616Z","dependency_job_id":"c6d2452d-50d8-493d-b0a4-b98207873784","html_url":"https://github.com/yzhao062/pyod","commit_stats":{"total_commits":1479,"total_committers":57,"mean_commits":25.94736842105263,"dds":0.5382014874915484,"last_synced_commit":"b95b82aac43140484d1ea64974085ff3a52276ea"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yzhao062%2Fpyod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yzhao062%2Fpyod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yzhao062%2Fpyod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yzhao062%2Fpyod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yzhao062","download_url":"https://codeload.github.com/yzhao062/pyod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745150,"owners_count":21957317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anomaly","anomaly-detection","autoencoder","data-analysis","data-mining","data-science","deep-learning","fraud-detection","machine-learning","neural-networks","novelty-detection","out-of-distribution-detection","outlier-detection","outlier-ensembles","outliers","python","python3","unsupervised-learning"],"created_at":"2024-07-30T22:01:01.260Z","updated_at":"2026-05-11T09:37:50.312Z","avatar_url":"https://github.com/yzhao062.png","language":"Python","funding_links":["https://github.com/sponsors/yzhao062"],"categories":["Multipurpose","Python","Papers","AI for *Ops","异常检测","Outlier and noise detection","Repos","\u003cspan id=\"head75\"\u003e Outlier Detection\u003c/span\u003e","Machine Learning Framework","Table of Contents","Industrial Materials","Others","Outlier Detection","Curated List","Machine Learning","Industry-strength Anomaly Detection","🐍 Python","Anomaly Detection Software","4.2 关键算法","Uncategorized"],"sub_categories":["Outiler","Observability \u0026 Monitoring with AI","Anomaly Detection","Tools","General-Purpose Machine Learning","Time Series Analysis","Useful Python Tools for Data Analysis","3.3 数据集","Uncategorized"],"readme":"Python Outlier Detection (PyOD) 3\r\n==================================\r\n\r\n**PyOD 3: Agentic Anomaly Detection At Scale**\r\n\r\n|badge_pypi| |badge_anaconda| |badge_docs| |badge_stars| |badge_forks| |badge_downloads| |badge_testing| |badge_coverage| |badge_maintainability| |badge_license| |badge_benchmark|\r\n\r\n.. |badge_pypi| image:: https://img.shields.io/pypi/v/pyod.svg?color=brightgreen\r\n   :target: https://pypi.org/project/pyod/\r\n   :alt: PyPI version\r\n\r\n.. |badge_anaconda| image:: https://anaconda.org/conda-forge/pyod/badges/version.svg\r\n   :target: https://anaconda.org/conda-forge/pyod\r\n   :alt: Anaconda version\r\n\r\n.. |badge_docs| image:: https://readthedocs.org/projects/pyod/badge/?version=latest\r\n   :target: https://pyod.readthedocs.io/en/latest/?badge=latest\r\n   :alt: Documentation status\r\n\r\n.. |badge_stars| image:: https://img.shields.io/github/stars/yzhao062/pyod.svg\r\n   :target: https://github.com/yzhao062/pyod/stargazers\r\n   :alt: GitHub stars\r\n\r\n.. |badge_forks| image:: https://img.shields.io/github/forks/yzhao062/pyod.svg?color=blue\r\n   :target: https://github.com/yzhao062/pyod/network\r\n   :alt: GitHub forks\r\n\r\n.. |badge_downloads| image:: https://pepy.tech/badge/pyod\r\n   :target: https://pepy.tech/project/pyod\r\n   :alt: Downloads\r\n\r\n.. |badge_testing| image:: https://github.com/yzhao062/pyod/actions/workflows/testing.yml/badge.svg\r\n   :target: https://github.com/yzhao062/pyod/actions/workflows/testing.yml\r\n   :alt: Testing\r\n\r\n\r\n.. |badge_coverage| image:: https://coveralls.io/repos/github/yzhao062/pyod/badge.svg\r\n   :target: https://coveralls.io/github/yzhao062/pyod\r\n   :alt: Coverage Status\r\n\r\n.. |badge_maintainability| image:: https://api.codeclimate.com/v1/badges/bdc3d8d0454274c753c4/maintainability\r\n   :target: https://codeclimate.com/github/yzhao062/Pyod/maintainability\r\n   :alt: Maintainability\r\n\r\n.. |badge_license| image:: https://img.shields.io/github/license/yzhao062/pyod.svg\r\n   :target: https://github.com/yzhao062/pyod/blob/master/LICENSE\r\n   :alt: License\r\n\r\n.. |badge_benchmark| image:: https://img.shields.io/badge/ADBench-benchmark_results-pink\r\n   :target: https://github.com/Minqi824/ADBench\r\n   :alt: Benchmark\r\n\r\n\r\n-----\r\n\r\n    **PyOD is now agentic.** Any AI agent can drive an expert-level anomaly detection investigation on your data in plain English. The classic ``fit``/``predict`` API stays unchanged.\r\n\r\n-----\r\n\r\nPyOD 3 is the most comprehensive Python library for anomaly detection. Four pillars:\r\n\r\n===========================  ========================================================================================\r\nPillar                       What it means\r\n===========================  ========================================================================================\r\nMulti-Modal                  60+ detectors across **tabular, time series, graph, text, and image** data, one API\r\nFull Lifecycle               From raw data to explained anomalies and next-step guidance in a single call\r\nAgentic                      Ask in plain English, and AI agents run expert-level detection without OD expertise\r\nMost Used                    38+ million downloads; benchmark-backed routing (ADBench, TSB-AD, BOND, NLP-ADBench)\r\n===========================  ========================================================================================\r\n\r\nInstall\r\n^^^^^^^\r\n\r\nCore library (required for every activation path):\r\n\r\n.. code-block:: bash\r\n\r\n    pip install pyod\r\n\r\nThen pick the activation path that matches your agent stack:\r\n\r\n.. code-block:: bash\r\n\r\n    # 1. Claude Code / Claude Desktop / Codex — enables the od-expert skill\r\n    pyod install skill              # Claude Code / Desktop: user-global (~/.claude/skills/)\r\n    pyod install skill --project    # Codex: project-local (./skills/, Codex has no user-global dir)\r\n\r\n    # 2. Any MCP-compatible LLM — requires the optional mcp extra\r\n    pip install pyod[mcp]\r\n    pyod mcp serve                 # alias for `python -m pyod.mcp_server`\r\n\r\n    # 3. Pure Python — no extra step\r\n    #    from pyod.utils.ad_engine import ADEngine\r\n\r\nRun ``pyod info`` at any time to see version, detector counts, and\r\nthe install state of each activation path. ``pyod info`` also detects\r\nwhich agent stack you have installed (``~/.claude/`` for Claude Code,\r\n``~/.codex/`` for Codex) and recommends the right install command.\r\n\r\nFor conda, source install, dependency details, and troubleshooting,\r\nsee the full `installation guide \u003chttps://pyod.readthedocs.io/en/latest/install.html\u003e`__.\r\nThe legacy ``pyod-install-skill`` command from v3.0.0 still works as an\r\nalias for ``pyod install skill``.\r\n\r\n**Outlier Detection with 5 Lines of Code** (``pip install pyod``):\r\n\r\n.. code-block:: python\r\n\r\n    from pyod.models.iforest import IForest\r\n    clf = IForest()\r\n    clf.fit(X_train)\r\n    y_train_scores = clf.decision_scores_          # training anomaly scores\r\n    y_test_scores = clf.decision_function(X_test)   # test anomaly scores\r\n\r\n**Three ways to use PyOD:**\r\n\r\n=========  =====================  ======================================================================  =======================================\r\nLayer      Name                   When to use                                                             Entry point\r\n=========  =====================  ======================================================================  =======================================\r\n1          Classic API            You know which detector you want                                        `Layer 1 examples \u003chttps://pyod.readthedocs.io/en/latest/examples/tabular.html\u003e`__\r\n2          ADEngine               You want PyOD to choose, compare, and assess automatically              `Layer 2 walkthrough \u003chttps://pyod.readthedocs.io/en/latest/examples/adengine.html\u003e`__\r\n3          Agentic Investigation  You want an AI agent to drive OD through natural conversation           `Layer 3 walkthrough \u003chttps://pyod.readthedocs.io/en/latest/examples/agentic.html\u003e`__\r\n=========  =====================  ======================================================================  =======================================\r\n\r\nLayers 2 and 3 are powered by ``ADEngine``, PyOD's intelligent orchestration core. Layer 3 adds two agentic activation paths: the ``od-expert`` skill for Claude Code and Codex, and an MCP server (``python -m pyod.mcp_server``) that works with any MCP-compatible LLM out of the box. See the Install block above for detailed setup instructions.\r\n\r\n.. image:: https://raw.githubusercontent.com/yzhao062/pyod/development/docs/figs/agentic-demo.png\r\n   :alt: PyOD 3 agentic investigation demo on cardiotocography dataset\r\n   :align: center\r\n   :width: 720\r\n\r\nThe figure above shows a real 5-turn agentic conversation on the UCI Cardiotocography dataset. See the `full walkthrough \u003chttps://pyod.readthedocs.io/en/latest/examples/agentic.html\u003e`__, runnable `agentic example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/agentic_example.py\u003e`__, or interactive `HTML demo \u003chttps://htmlpreview.github.io/?https://github.com/yzhao062/pyod/blob/development/examples/agentic_demo.html\u003e`__.\r\n\r\n**PyOD Ecosystem \u0026 Resources**:\r\n`NLP-ADBench \u003chttps://github.com/USC-FORTIS/NLP-ADBench\u003e`__ (NLP anomaly detection) | `TODS \u003chttps://github.com/datamllab/tods\u003e`__ (time-series) | `PyGOD \u003chttps://pygod.org/\u003e`__ (graph) | `ADBench \u003chttps://github.com/Minqi824/ADBench\u003e`__ (benchmark) | `AD-LLM \u003chttps://arxiv.org/abs/2412.11142\u003e`__ (LLM-based AD) [#Yang2024ad]_ | `Resources \u003chttps://github.com/yzhao062/anomaly-detection-resources\u003e`__\r\n\r\n----\r\n\r\n\r\nAbout PyOD\r\n^^^^^^^^^^\r\n\r\nPyOD, established in 2017, is the longest-running and most widely used Python library for anomaly detection. With `38+ million downloads \u003chttps://pepy.tech/project/pyod\u003e`__, it serves both academic research (featured in `Analytics Vidhya \u003chttps://www.analyticsvidhya.com/blog/2019/02/outlier-detection-python-pyod/\u003e`__, `KDnuggets \u003chttps://www.kdnuggets.com/2019/02/outlier-detection-methods-cheat-sheet.html\u003e`__, and `Towards Data Science \u003chttps://towardsdatascience.com/anomaly-detection-for-dummies-15f148e559c1\u003e`__) and commercial products.\r\n\r\nV3 extends the library with ``ADEngine`` (intelligent orchestration) and the ``od-expert`` skill (agentic workflow), while keeping the classic ``fit``/``predict`` API fully backward-compatible. V3 is built on SUOD [#Zhao2021SUOD]_ for fast parallel training and numba JIT for per-model speedups.\r\n\r\n**Impact \u0026 Recognition**:\r\n\r\n===================================  ===========================================================================\r\nArea                                 Examples\r\n===================================  ===========================================================================\r\nSpace \u0026 science                      European Space Agency `OPS-SAT spacecraft telemetry benchmark \u003chttps://www.nature.com/articles/s41597-025-05035-3\u003e`__ (*Nature Scientific Data*, 2025) uses PyOD for all 30 algorithms.\r\nEnterprise deployment                Walmart (1M+ daily pricing updates, KDD 2019), Databricks (Kakapo framework integrating PyOD with MLflow/Hyperopt; insider-threat detection solution), IQVIA (123K+ pharmacy claims), Altair AI Studio, Ericsson (patent `WO2023166515A1 \u003chttps://patents.google.com/patent/WO2023166515A1\u003e`__).\r\nBooks                                `Outlier Detection in Python \u003chttps://www.manning.com/books/outlier-detection-in-python\u003e`__ (Brett Kennedy, Manning); *Handbook of Anomaly Detection with Python* (Chris Kuo, Columbia); `Finding Ghosts in Your Data \u003chttps://link.springer.com/book/10.1007/978-1-4842-8870-2\u003e`__ (Kevin Feasel, Apress).\r\nCourses                              DataCamp `Anomaly Detection in Python \u003chttps://www.datacamp.com/courses/anomaly-detection-in-python\u003e`__ (19M+ platform learners), Manning `liveProject \u003chttps://www.manning.com/liveproject/using-pyod-and-ensembles-methods\u003e`__, O'Reilly video edition, multiple Udemy courses.\r\nPodcasts                             `Talk Python To Me #497 \u003chttps://talkpython.fm/episodes/show/497/outlier-detection-with-python\u003e`__, `Real Python Podcast #208 \u003chttps://realpython.com/podcasts/rpp/208/\u003e`__.\r\nInternational                        Tutorials in 5 non-English languages: Chinese (CSDN, Zhihu, 搜狐, 机器之心, `aidoczh.com \u003chttps://www.aidoczh.com\u003e`__ full doc translation), Japanese, Korean, German, Spanish.\r\n===================================  ===========================================================================\r\n\r\nSee the `full impact page \u003chttps://pyod.readthedocs.io/en/latest/impact.html\u003e`__ on Read the Docs for the complete list of citations, enterprise deployments, patents, and media coverage.\r\n\r\n**Citing PyOD**:\r\n\r\nIf you use PyOD in a scientific publication, we would appreciate citations to the following paper(s):\r\n\r\n`PyOD 2: A Python Library for Outlier Detection with LLM-powered Model Selection \u003chttps://arxiv.org/abs/2412.12154\u003e`__ is available as a preprint. If you use PyOD in a scientific publication, we would appreciate citations to the following paper::\r\n\r\n    @inproceedings{chen2025pyod,\r\n      title={Pyod 2: A python library for outlier detection with llm-powered model selection},\r\n      author={Chen, Sihan and Qian, Zhuangzhuang and Siu, Wingchun and Hu, Xingcan and Li, Jiaqi and Li, Shawn and Qin, Yuehan and Yang, Tiankai and Xiao, Zhuo and Ye, Wanghao and others},\r\n      booktitle={Companion Proceedings of the ACM on Web Conference 2025},\r\n      pages={2807--2810},\r\n      year={2025}\r\n    }\r\n\r\n\r\n`PyOD paper \u003chttp://www.jmlr.org/papers/volume20/19-011/19-011.pdf\u003e`__ is published in `Journal of Machine Learning Research (JMLR) \u003chttp://www.jmlr.org/\u003e`__ (MLOSS track).::\r\n\r\n    @article{zhao2019pyod,\r\n        author  = {Zhao, Yue and Nasrullah, Zain and Li, Zheng},\r\n        title   = {PyOD: A Python Toolbox for Scalable Outlier Detection},\r\n        journal = {Journal of Machine Learning Research},\r\n        year    = {2019},\r\n        volume  = {20},\r\n        number  = {96},\r\n        pages   = {1-7},\r\n        url     = {http://jmlr.org/papers/v20/19-011.html}\r\n    }\r\n\r\nor::\r\n\r\n    Zhao, Y., Nasrullah, Z. and Li, Z., 2019. PyOD: A Python Toolbox for Scalable Outlier Detection. Journal of machine learning research (JMLR), 20(96), pp.1-7.\r\n\r\n\r\nFor a broader perspective on anomaly detection, see our NeurIPS papers on `ADBench \u003chttps://arxiv.org/abs/2206.09426\u003e`__ [#Han2022ADBench]_ and `ADGym \u003chttps://arxiv.org/abs/2309.15376\u003e`__.\r\n\r\n\r\n**Table of Contents**:\r\n\r\n* `API Cheatsheet \u0026 Reference \u003c#api-cheatsheet--reference\u003e`__\r\n* `Benchmarks \u003c#benchmarks\u003e`__\r\n* `Implemented Algorithms \u003c#implemented-algorithms\u003e`__ (Tabular, Time Series, Graph, Embedding)\r\n* `Additional Topics \u003c#additional-topics\u003e`__ (Model Save/Load, SUOD, Thresholding)\r\n* `Quick Start for Outlier Detection \u003c#quick-start-for-outlier-detection\u003e`__\r\n* `How to Contribute \u003c#how-to-contribute\u003e`__\r\n* `Inclusion Criteria \u003c#inclusion-criteria\u003e`__\r\n\r\n----\r\n\r\n\r\nAPI Cheatsheet \u0026 Reference\r\n^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n\r\nThe full API Reference is split by modality at `PyOD Documentation \u003chttps://pyod.readthedocs.io/en/latest/\u003e`__: `Tabular \u003chttps://pyod.readthedocs.io/en/latest/pyod.models.tabular.html\u003e`__, `Time Series \u003chttps://pyod.readthedocs.io/en/latest/pyod.models.timeseries.html\u003e`__, `Graph \u003chttps://pyod.readthedocs.io/en/latest/pyod.models.graph.html\u003e`__, `Embedding \u003chttps://pyod.readthedocs.io/en/latest/pyod.models.embedding.html\u003e`__, `ADEngine \u003chttps://pyod.readthedocs.io/en/latest/pyod.ad_engine.html\u003e`__, `Utilities \u003chttps://pyod.readthedocs.io/en/latest/pyod.utils.html\u003e`__. Below is a quick cheatsheet for all detectors:\r\n\r\n* **fit(X)**: Fit the detector. The parameter y is ignored in unsupervised methods.\r\n* **decision_function(X)**: Predict raw anomaly scores for X using the fitted detector.\r\n* **predict(X)**: Determine whether a sample is an outlier or not as binary labels using the fitted detector.\r\n* **predict_proba(X)**: Estimate the probability of a sample being an outlier using the fitted detector.\r\n* **predict_confidence(X)**: Assess the model's confidence on a per-sample basis (applicable in predict and predict_proba) [#Perini2020Quantifying]_.\r\n* **predict_with_rejection(X)**\\ : Allow the detector to reject (i.e., abstain from making) highly uncertain predictions (output = -2) [#Perini2023Rejection]_.\r\n\r\n**Key Attributes of a fitted model**:\r\n\r\n* **decision_scores_**: Outlier scores of the training data. Higher scores typically indicate more abnormal behavior. Outliers usually have higher scores.\r\n* **labels_**: Binary labels of the training data, where 0 indicates inliers and 1 indicates outliers/anomalies.\r\n\r\n\r\n----\r\n\r\n\r\nBenchmarks\r\n^^^^^^^^^^\r\n\r\n* `ADBench \u003chttps://github.com/Minqi824/ADBench\u003e`__ [#Han2022ADBench]_: 30 algorithms on 57 tabular datasets. See `comparison \u003chttps://github.com/yzhao062/pyod/blob/master/examples/compare_all_models.py\u003e`__.\r\n* `NLP-ADBench \u003chttps://github.com/USC-FORTIS/NLP-ADBench\u003e`__: 19 methods on 8 text datasets. Two-step (embedding + detector) beats end-to-end.\r\n* `TSB-AD \u003chttps://github.com/TheDatumOrg/TSB-AD\u003e`__ [#Liu2024TSB]_: 40 algorithms on 1070 time series datasets (NeurIPS 2024).\r\n* `BOND \u003chttps://arxiv.org/abs/2206.10071\u003e`__ [#Liu2022BOND]_: 14 graph anomaly detection algorithms on 14 datasets (NeurIPS 2022).\r\n\r\n----\r\n\r\nAdditional Topics\r\n^^^^^^^^^^^^^^^^^\r\n\r\n* `Model Save \u0026 Load \u003chttps://pyod.readthedocs.io/en/latest/model_persistence.html\u003e`__: Use joblib or pickle for saving and loading PyOD models. See `example \u003chttps://github.com/yzhao062/pyod/blob/master/examples/save_load_model_example.py\u003e`__.\r\n* `Fast Train with SUOD \u003chttps://pyod.readthedocs.io/en/latest/fast_train.html\u003e`__: Accelerate training and prediction with the SUOD framework [#Zhao2021SUOD]_. See `example \u003chttps://github.com/yzhao062/pyod/blob/master/examples/suod_example.py\u003e`__.\r\n* `Thresholding Outlier Scores \u003chttps://pyod.readthedocs.io/en/latest/thresholding.html\u003e`__: Data-driven approaches for setting contamination levels via `PyThresh \u003chttps://github.com/KulikDM/pythresh\u003e`__.\r\n\r\n----\r\n\r\n\r\n\r\nImplemented Algorithms\r\n^^^^^^^^^^^^^^^^^^^^^^\r\n\r\nPyOD is organized into two functional groups: **(i) Detection Algorithms**, with dedicated subsections for tabular, time series, and graph data (EmbeddingOD inside the tabular table adds multi-modal support for text and image via foundation model encoders); and **(ii) Utility Functions** for data generation, evaluation, and intelligent orchestration.\r\n\r\n**(i-a) Tabular \u0026 Multi-Modal Detection Algorithms** :\r\n\r\n.. list-table::\r\n   :widths: 15 14 58 5 8\r\n   :header-rows: 1\r\n\r\n   * - Type\r\n     - Abbr\r\n     - Algorithm\r\n     - Year\r\n     - Ref\r\n   * - Probabilistic\r\n     - ECOD\r\n     - Unsupervised Outlier Detection Using Empirical Cumulative Distribution Functions (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/ecod_example.py\u003e`__)\r\n     - 2022\r\n     - [#Li2021ECOD]_\r\n   * - Probabilistic\r\n     - ABOD\r\n     - Angle-Based Outlier Detection (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/abod_example.py\u003e`__)\r\n     - 2008\r\n     - [#Kriegel2008Angle]_\r\n   * - Probabilistic\r\n     - FastABOD\r\n     - Fast Angle-Based Outlier Detection using approximation (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/abod_example.py\u003e`__)\r\n     - 2008\r\n     - [#Kriegel2008Angle]_\r\n   * - Probabilistic\r\n     - COPOD\r\n     - COPOD: Copula-Based Outlier Detection (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/copod_example.py\u003e`__)\r\n     - 2020\r\n     - [#Li2020COPOD]_\r\n   * - Probabilistic\r\n     - MAD\r\n     - Median Absolute Deviation (MAD) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/mad_example.py\u003e`__)\r\n     - 1993\r\n     - [#Iglewicz1993How]_\r\n   * - Probabilistic\r\n     - SOS\r\n     - Stochastic Outlier Selection (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/sos_example.py\u003e`__)\r\n     - 2012\r\n     - [#Janssens2012Stochastic]_\r\n   * - Probabilistic\r\n     - QMCD\r\n     - Quasi-Monte Carlo Discrepancy outlier detection (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/qmcd_example.py\u003e`__)\r\n     - 2001\r\n     - [#Fang2001Wrap]_\r\n   * - Probabilistic\r\n     - KDE\r\n     - Outlier Detection with Kernel Density Functions (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/kde_example.py\u003e`__)\r\n     - 2007\r\n     - [#Latecki2007Outlier]_\r\n   * - Probabilistic\r\n     - Sampling\r\n     - Rapid distance-based outlier detection via sampling (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/sampling_example.py\u003e`__)\r\n     - 2013\r\n     - [#Sugiyama2013Rapid]_\r\n   * - Probabilistic\r\n     - GMM\r\n     - Probabilistic Mixture Modeling for Outlier Analysis (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/gmm_example.py\u003e`__)\r\n     -\r\n     - [#Aggarwal2015Outlier]_ [Ch.2]\r\n   * - Linear Model\r\n     - PCA\r\n     - Principal Component Analysis (sum of weighted projected distances to eigenvector hyperplanes) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/pca_example.py\u003e`__)\r\n     - 2003\r\n     - [#Shyu2003A]_\r\n   * - Linear Model\r\n     - KPCA\r\n     - Kernel Principal Component Analysis (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/kpca_example.py\u003e`__)\r\n     - 2007\r\n     - [#Hoffmann2007Kernel]_\r\n   * - Linear Model\r\n     - MCD\r\n     - Minimum Covariance Determinant (Mahalanobis distances as outlier scores) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/mcd_example.py\u003e`__)\r\n     - 1999\r\n     - [#Hardin2004Outlier]_ [#Rousseeuw1999A]_\r\n   * - Linear Model\r\n     - CD\r\n     - Cook's distance for outlier detection (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/cd_example.py\u003e`__)\r\n     - 1977\r\n     - [#Cook1977Detection]_\r\n   * - Linear Model\r\n     - OCSVM\r\n     - One-Class Support Vector Machines (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/ocsvm_example.py\u003e`__)\r\n     - 2001\r\n     - [#Scholkopf2001Estimating]_\r\n   * - Linear Model\r\n     - LMDD\r\n     - Deviation-based Outlier Detection (LMDD) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/lmdd_example.py\u003e`__)\r\n     - 1996\r\n     - [#Arning1996A]_\r\n   * - Proximity-Based\r\n     - LOF\r\n     - Local Outlier Factor (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/lof_example.py\u003e`__)\r\n     - 2000\r\n     - [#Breunig2000LOF]_\r\n   * - Proximity-Based\r\n     - COF\r\n     - Connectivity-Based Outlier Factor (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/cof_example.py\u003e`__)\r\n     - 2002\r\n     - [#Tang2002Enhancing]_\r\n   * - Proximity-Based\r\n     - (Incr.) COF\r\n     - Memory Efficient Connectivity-Based Outlier Factor (slower, reduced storage) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/cof_example.py\u003e`__)\r\n     - 2002\r\n     - [#Tang2002Enhancing]_\r\n   * - Proximity-Based\r\n     - CBLOF\r\n     - Clustering-Based Local Outlier Factor (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/cblof_example.py\u003e`__)\r\n     - 2003\r\n     - [#He2003Discovering]_\r\n   * - Proximity-Based\r\n     - LOCI\r\n     - LOCI: Fast outlier detection via local correlation integral (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/loci_example.py\u003e`__)\r\n     - 2003\r\n     - [#Papadimitriou2003LOCI]_\r\n   * - Proximity-Based\r\n     - HBOS\r\n     - Histogram-based Outlier Score (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/hbos_example.py\u003e`__)\r\n     - 2012\r\n     - [#Goldstein2012Histogram]_\r\n   * - Proximity-Based\r\n     - HDBSCAN\r\n     - Density-based clustering via hierarchical density estimates (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/hdbscan_example.py\u003e`__)\r\n     - 2013\r\n     - [#Campello2013Density]_\r\n   * - Proximity-Based\r\n     - kNN\r\n     - k Nearest Neighbors (distance to k-th neighbor as outlier score) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/knn_example.py\u003e`__)\r\n     - 2000\r\n     - [#Ramaswamy2000Efficient]_\r\n   * - Proximity-Based\r\n     - AvgKNN\r\n     - Average kNN (average distance to k neighbors as outlier score) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/knn_example.py\u003e`__)\r\n     - 2002\r\n     - [#Angiulli2002Fast]_\r\n   * - Proximity-Based\r\n     - MedKNN\r\n     - Median kNN (median distance to k neighbors as outlier score) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/knn_example.py\u003e`__)\r\n     - 2002\r\n     - [#Angiulli2002Fast]_\r\n   * - Proximity-Based\r\n     - SOD\r\n     - Subspace Outlier Detection (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/sod_example.py\u003e`__)\r\n     - 2009\r\n     - [#Kriegel2009Outlier]_\r\n   * - Proximity-Based\r\n     - ROD\r\n     - Rotation-based Outlier Detection (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/rod_example.py\u003e`__)\r\n     - 2020\r\n     - [#Almardeny2020A]_\r\n   * - Outlier Ensembles\r\n     - IForest\r\n     - Isolation Forest (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/iforest_example.py\u003e`__)\r\n     - 2008\r\n     - [#Liu2008Isolation]_\r\n   * - Outlier Ensembles\r\n     - INNE\r\n     - Isolation-based Anomaly Detection via Nearest-Neighbor Ensembles (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/inne_example.py\u003e`__)\r\n     - 2018\r\n     - [#Bandaragoda2018Isolation]_\r\n   * - Outlier Ensembles\r\n     - DIF\r\n     - Deep Isolation Forest for Anomaly Detection (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/dif_example.py\u003e`__)\r\n     - 2023\r\n     - [#Xu2023Deep]_\r\n   * - Outlier Ensembles\r\n     - FB\r\n     - Feature Bagging (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/feature_bagging_example.py\u003e`__)\r\n     - 2005\r\n     - [#Lazarevic2005Feature]_\r\n   * - Outlier Ensembles\r\n     - LSCP\r\n     - LSCP: Locally Selective Combination of Parallel Outlier Ensembles (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/lscp_example.py\u003e`__)\r\n     - 2019\r\n     - [#Zhao2019LSCP]_\r\n   * - Outlier Ensembles\r\n     - XGBOD\r\n     - Extreme Boosting Based Outlier Detection **(Supervised)** (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/xgbod_example.py\u003e`__)\r\n     - 2018\r\n     - [#Zhao2018XGBOD]_\r\n   * - Outlier Ensembles\r\n     - LODA\r\n     - Lightweight On-line Detector of Anomalies (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/loda_example.py\u003e`__)\r\n     - 2016\r\n     - [#Pevny2016Loda]_\r\n   * - Outlier Ensembles\r\n     - SUOD\r\n     - SUOD: Accelerating Large-scale Unsupervised Heterogeneous OD **(Acceleration)** (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/suod_example.py\u003e`__)\r\n     - 2021\r\n     - [#Zhao2021SUOD]_\r\n   * - Neural Networks\r\n     - AutoEncoder\r\n     - Fully connected AutoEncoder (reconstruction error as outlier score) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/auto_encoder_example.py\u003e`__)\r\n     -\r\n     - [#Aggarwal2015Outlier]_ [Ch.3]\r\n   * - Neural Networks\r\n     - VAE\r\n     - Variational AutoEncoder (reconstruction error as outlier score) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/vae_example.py\u003e`__)\r\n     - 2013\r\n     - [#Kingma2013Auto]_\r\n   * - Neural Networks\r\n     - Beta-VAE\r\n     - Variational AutoEncoder with customized loss (gamma and capacity) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/vae_example.py\u003e`__)\r\n     - 2018\r\n     - [#Burgess2018Understanding]_\r\n   * - Neural Networks\r\n     - SO_GAAL\r\n     - Single-Objective Generative Adversarial Active Learning (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/so_gaal_example.py\u003e`__)\r\n     - 2019\r\n     - [#Liu2019Generative]_\r\n   * - Neural Networks\r\n     - MO_GAAL\r\n     - Multiple-Objective Generative Adversarial Active Learning (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/mo_gaal_example.py\u003e`__)\r\n     - 2019\r\n     - [#Liu2019Generative]_\r\n   * - Neural Networks\r\n     - DeepSVDD\r\n     - Deep One-Class Classification (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/deepsvdd_example.py\u003e`__)\r\n     - 2018\r\n     - [#Ruff2018Deep]_\r\n   * - Neural Networks\r\n     - AnoGAN\r\n     - Anomaly Detection with Generative Adversarial Networks\r\n     - 2017\r\n     - [#Schlegl2017Unsupervised]_\r\n   * - Neural Networks\r\n     - ALAD\r\n     - Adversarially learned anomaly detection (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/alad_example.py\u003e`__)\r\n     - 2018\r\n     - [#Zenati2018Adversarially]_\r\n   * - Neural Networks\r\n     - AE1SVM\r\n     - Autoencoder-based One-class Support Vector Machine (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/ae1svm_example.py\u003e`__)\r\n     - 2019\r\n     - [#Nguyen2019scalable]_\r\n   * - Neural Networks\r\n     - DevNet\r\n     - Deep Anomaly Detection with Deviation Networks (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/devnet_example.py\u003e`__)\r\n     - 2019\r\n     - [#Pang2019Deep]_\r\n   * - Graph-based\r\n     - R-Graph\r\n     - Outlier detection by R-graph (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/rgraph_example.py\u003e`__)\r\n     - 2017\r\n     - [#You2017Provable]_\r\n   * - Graph-based\r\n     - LUNAR\r\n     - LUNAR: Unifying Local OD Methods via Graph Neural Networks (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/lunar_example.py\u003e`__)\r\n     - 2022\r\n     - [#Goodge2022Lunar]_\r\n   * - Embedding-based\r\n     - EmbeddingOD\r\n     - Multi-modal anomaly detection via foundation model embeddings, text and image (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/embedding_od_example.py\u003e`__)\r\n     - 2025\r\n     - [#Li2024NLPADBench]_\r\n\r\n\r\nEnsemble methods (IForest, INNE, DIF, FB, LSCP, LODA, SUOD, XGBOD) are included in the table above. Score combination functions (average, maximization, AOM, MOA, median, majority vote) are in ``pyod.models.combination``. See `API docs \u003chttps://pyod.readthedocs.io/en/latest/pyod.models.tabular.html\u003e`__ for details.\r\n\r\n\r\n**(i-b) Time Series Anomaly Detection** :\r\n\r\nAll time series detectors use the same ``fit``/``predict``/``decision_function`` API as tabular detectors, with one exception: ``MatrixProfile`` is transductive (train-only; use ``decision_scores_`` and ``labels_`` after ``fit()``, no out-of-sample ``predict``).\r\n\r\n**Input format**: numpy array of shape ``(n_timestamps,)`` for univariate or ``(n_timestamps, n_channels)`` for multivariate. Each row is one timestep; columns are channels/features. Pandas DataFrames and lists are auto-converted. **Output**: ``decision_scores_`` of shape ``(n_timestamps,)`` with one anomaly score per timestep.\r\n\r\n**Time series detection in 3 lines**:\r\n\r\n.. code-block:: python\r\n\r\n    from pyod.models.ts_kshape import KShape      # or any TS detector\r\n    clf = KShape(window_size=20)\r\n    clf.fit(X_train)                               # shape (n_timestamps,) or (n_timestamps, n_channels)\r\n    scores = clf.decision_scores_                  # per-timestamp anomaly scores\r\n\r\nAlgorithm rankings from `TSB-AD benchmark \u003chttps://github.com/TheDatumOrg/TSB-AD\u003e`__ [#Liu2024TSB]_ (NeurIPS 2024, 1070 datasets):\r\n\r\n.. list-table::\r\n   :widths: 15 18 50 5 12\r\n   :header-rows: 1\r\n\r\n   * - Type\r\n     - Abbr\r\n     - Algorithm\r\n     - Year\r\n     - Ref\r\n   * - Windowed Bridge\r\n     - TimeSeriesOD\r\n     - Any PyOD detector on sliding windows (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/ts_od_example.py\u003e`__)\r\n     - 2026\r\n     -\r\n   * - Subsequence\r\n     - MatrixProfile\r\n     - Matrix Profile via STOMP, transductive (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/ts_matrix_profile_example.py\u003e`__)\r\n     - 2016\r\n     - [#Yeh2016Matrix]_\r\n   * - Frequency\r\n     - SpectralResidual\r\n     - Spectral Residual: FFT-based saliency (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/ts_spectral_residual_example.py\u003e`__)\r\n     - 2019\r\n     - [#Ren2019Time]_\r\n   * - Clustering\r\n     - KShape\r\n     - k-Shape clustering (#2 in TSB-AD) (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/ts_kshape_example.py\u003e`__)\r\n     - 2015\r\n     - [#Paparrizos2015KShape]_\r\n   * - Streaming\r\n     - SAND\r\n     - Streaming with drift adaptation, experimental (`example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/ts_sand_example.py\u003e`__)\r\n     - 2021\r\n     - [#Boniol2021SAND]_\r\n   * - Deep Learning\r\n     - LSTMAD\r\n     - LSTM prediction error + Mahalanobis scoring\r\n     - 2015\r\n     - [#Malhotra2015Long]_\r\n   * - Deep Learning\r\n     - AnomalyTransformer\r\n     - Transformer with association discrepancy (experimental)\r\n     - 2022\r\n     - [#Xu2022Anomaly]_\r\n\r\n\r\n**(i-c) Graph Anomaly Detection** (``pip install pyod[graph]``):\r\n\r\nAll graph detectors are **transductive** in v1: use ``decision_scores_`` and ``labels_`` after ``fit()``. No out-of-sample ``predict``. Input: PyG ``Data`` object with ``x`` (node features) and ``edge_index`` (COO edges). SCAN works without features.\r\n\r\n**Graph detection in 3 lines** (``pip install pyod[graph]``):\r\n\r\n.. code-block:: python\r\n\r\n    from pyod.models.pyg_dominant import DOMINANT\r\n    clf = DOMINANT(hidden_dim=64, epochs=100)\r\n    clf.fit(data)                                  # PyG Data object\r\n    scores = clf.decision_scores_                  # per-node anomaly scores\r\n\r\nAlgorithm rankings from `BOND benchmark \u003chttps://arxiv.org/abs/2206.10071\u003e`__ [#Liu2022BOND]_ (NeurIPS 2022, 14 datasets):\r\n\r\n.. list-table::\r\n   :widths: 18 18 45 5 14\r\n   :header-rows: 1\r\n\r\n   * - Type\r\n     - Abbr\r\n     - Algorithm\r\n     - Year\r\n     - Ref\r\n   * - GCN Autoencoder\r\n     - DOMINANT\r\n     - GCN AE, structure + attribute reconstruction (#1 BOND deep) (`dominant example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/pyg_dominant_example.py\u003e`__)\r\n     - 2019\r\n     - [#Ding2019DOMINANT]_\r\n   * - Contrastive\r\n     - CoLA\r\n     - Contrastive self-supervised, local neighbor context (#2 BOND deep) (`cola example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/pyg_cola_example.py\u003e`__)\r\n     - 2022\r\n     - [#Liu2022CoLA]_\r\n   * - Contrastive+AE\r\n     - CONAD\r\n     - Contrastive with anomalous-view injection + dual reconstruction (`conad example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/pyg_conad_example.py\u003e`__)\r\n     - 2022\r\n     - [#Xu2022CONAD]_\r\n   * - Attention AE\r\n     - AnomalyDAE\r\n     - GAT structure encoder + MLP attribute encoder (`anomalydae example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/pyg_anomalydae_example.py\u003e`__)\r\n     - 2020\r\n     - [#Fan2020AnomalyDAE]_\r\n   * - Motif AE\r\n     - GUIDE\r\n     - Dual GCN AE on original + triangle-motif adjacency (`guide example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/pyg_guide_example.py\u003e`__)\r\n     - 2021\r\n     - [#Yuan2021GUIDE]_\r\n   * - Matrix Factor.\r\n     - Radar\r\n     - Residual analysis via matrix factorization (`radar example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/pyg_radar_example.py\u003e`__)\r\n     - 2017\r\n     - [#Li2017Radar]_\r\n   * - Matrix Factor.\r\n     - ANOMALOUS\r\n     - Joint MF with Laplacian regularization (`anomalous example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/pyg_anomalous_example.py\u003e`__)\r\n     - 2018\r\n     - [#Peng2018ANOMALOUS]_\r\n   * - Structural\r\n     - SCAN\r\n     - Structural clustering, no features needed (`scan example \u003chttps://github.com/yzhao062/pyod/blob/development/examples/pyg_scan_example.py\u003e`__)\r\n     - 2007\r\n     - [#Xu2007SCAN]_\r\n\r\n\r\n**(ii) Utility Functions**:\r\n\r\n===================  ============================  =====================================================================================================================================================\r\nType                 Name                          Function\r\n===================  ============================  =====================================================================================================================================================\r\nData                 generate_data                 Synthesized data generation; normal data from multivariate Gaussian, outliers from uniform distribution\r\nData                 generate_data_clusters        Synthesized data generation in clusters for more complex patterns\r\nEvaluation           evaluate_print                Print ROC-AUC and Precision @ Rank n for a detector\r\nEvaluation           precision_n_scores            Calculate Precision @ Rank n\r\nUtility              get_label_n                   Turn raw outlier scores into binary labels by assigning 1 to the top n scores\r\nStat                 wpearsonr                     Calculate the weighted Pearson correlation of two samples\r\nEncoding             resolve_encoder               Resolve an encoder from a string name, BaseEncoder instance, or callable\r\nEncoding             SentenceTransformerEncoder     Encode text via sentence-transformers models (e.g., MiniLM, mpnet)\r\nEncoding             OpenAIEncoder                 Encode text via OpenAI Embeddings API (text-embedding-3-small/large)\r\nEncoding             HuggingFaceEncoder            Encode text or images via HuggingFace transformers (BERT, DINOv2, CLIP)\r\n===================  ============================  =====================================================================================================================================================\r\n\r\n----\r\n\r\nQuick Start for Outlier Detection\r\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n\r\nPyOD has been well acknowledged by the machine learning community with a few featured posts and tutorials.\r\n\r\n**Analytics Vidhya**: `An Awesome Tutorial to Learn Outlier Detection in Python using PyOD Library \u003chttps://www.analyticsvidhya.com/blog/2019/02/outlier-detection-python-pyod/\u003e`__\r\n\r\n**KDnuggets**: `Intuitive Visualization of Outlier Detection Methods \u003chttps://www.kdnuggets.com/2019/02/outlier-detection-methods-cheat-sheet.html\u003e`__, `An Overview of Outlier Detection Methods from PyOD \u003chttps://www.kdnuggets.com/2019/06/overview-outlier-detection-methods-pyod.html\u003e`__\r\n\r\n**Towards Data Science**: `Anomaly Detection for Dummies \u003chttps://towardsdatascience.com/anomaly-detection-for-dummies-15f148e559c1\u003e`__\r\n\r\n`\"examples/knn_example.py\" \u003chttps://github.com/yzhao062/pyod/blob/master/examples/knn_example.py\u003e`__\r\ndemonstrates the basic API of using kNN detector. **It is noted that the API across all other algorithms are consistent/similar**.\r\n\r\nMore detailed instructions for running examples can be found in `examples directory \u003chttps://github.com/yzhao062/pyod/blob/master/examples\u003e`__.\r\n\r\n\r\n#. Initialize a kNN detector, fit the model, and make the prediction.\r\n\r\n   .. code-block:: python\r\n\r\n\r\n       from pyod.models.knn import KNN   # kNN detector\r\n\r\n       # train kNN detector\r\n       clf_name = 'KNN'\r\n       clf = KNN()\r\n       clf.fit(X_train)\r\n\r\n       # get the prediction label and outlier scores of the training data\r\n       y_train_pred = clf.labels_  # binary labels (0: inliers, 1: outliers)\r\n       y_train_scores = clf.decision_scores_  # raw outlier scores\r\n\r\n       # get the prediction on the test data\r\n       y_test_pred = clf.predict(X_test)  # outlier labels (0 or 1)\r\n       y_test_scores = clf.decision_function(X_test)  # outlier scores\r\n\r\n       # it is possible to get the prediction confidence as well\r\n       y_test_pred, y_test_pred_confidence = clf.predict(X_test, return_confidence=True)  # outlier labels (0 or 1) and confidence in the range of [0,1]\r\n\r\n#. Evaluate the prediction by ROC and Precision @ Rank n (p@n).\r\n\r\n   .. code-block:: python\r\n\r\n       from pyod.utils.data import evaluate_print\r\n       \r\n       # evaluate and print the results\r\n       print(\"\\nOn Training Data:\")\r\n       evaluate_print(clf_name, y_train, y_train_scores)\r\n       print(\"\\nOn Test Data:\")\r\n       evaluate_print(clf_name, y_test, y_test_scores)\r\n\r\n\r\n#. See a sample output \u0026 visualization.\r\n\r\n\r\n   .. code-block:: python\r\n\r\n\r\n       On Training Data:\r\n       KNN ROC:1.0, precision @ rank n:1.0\r\n\r\n       On Test Data:\r\n       KNN ROC:0.9989, precision @ rank n:0.9\r\n\r\n   .. code-block:: python\r\n\r\n\r\n       visualize(clf_name, X_train, y_train, X_test, y_test, y_train_pred,\r\n           y_test_pred, show_figure=True, save_figure=False)\r\n\r\n----\r\n\r\nReference\r\n^^^^^^^^^\r\n\r\n\r\n.. [#Aggarwal2015Outlier] Aggarwal, C.C., 2015. Outlier analysis. In Data mining (pp. 237-263). Springer, Cham.\r\n\r\n.. [#Aggarwal2015Theoretical] Aggarwal, C.C. and Sathe, S., 2015. Theoretical foundations and algorithms for outlier ensembles.\\ *ACM SIGKDD Explorations Newsletter*\\ , 17(1), pp.24-47.\r\n\r\n.. [#Aggarwal2017Outlier] Aggarwal, C.C. and Sathe, S., 2017. Outlier ensembles: An introduction. Springer.\r\n\r\n.. [#Almardeny2020A] Almardeny, Y., Boujnah, N. and Cleary, F., 2020. A Novel Outlier Detection Method for Multivariate Data. *IEEE Transactions on Knowledge and Data Engineering*.\r\n\r\n.. [#Angiulli2002Fast] Angiulli, F. and Pizzuti, C., 2002, August. Fast outlier detection in high dimensional spaces. In *European Conference on Principles of Data Mining and Knowledge Discovery* pp. 15-27.\r\n\r\n.. [#Arning1996A] Arning, A., Agrawal, R. and Raghavan, P., 1996, August. A Linear Method for Deviation Detection in Large Databases. In *KDD* (Vol. 1141, No. 50, pp. 972-981).\r\n\r\n.. [#Bandaragoda2018Isolation] Bandaragoda, T. R., Ting, K. M., Albrecht, D., Liu, F. T., Zhu, Y., and Wells, J. R., 2018, Isolation-based anomaly detection using nearest-neighbor ensembles. *Computational Intelligence*\\ , 34(4), pp. 968-998.\r\n\r\n.. [#Breunig2000LOF] Breunig, M.M., Kriegel, H.P., Ng, R.T. and Sander, J., 2000, May. LOF: identifying density-based local outliers. *ACM Sigmod Record*\\ , 29(2), pp. 93-104.\r\n\r\n.. [#Burgess2018Understanding] Burgess, Christopher P., et al. \"Understanding disentangling in beta-VAE.\" arXiv preprint arXiv:1804.03599 (2018).\r\n\r\n.. [#Campello2013Density] Campello, R.J.G.B., Moulavi, D. and Sander, J., 2013, April. Density-based clustering based on hierarchical density estimates. In *Pacific-Asia Conference on Knowledge Discovery and Data Mining* (pp. 160-172). Springer.\r\n\r\n.. [#Cook1977Detection] Cook, R.D., 1977. Detection of influential observation in linear regression. Technometrics, 19(1), pp.15-18.\r\n\r\n.. [#Chen2024PyOD] Chen, S., Qian, Z., Siu, W., Hu, X., Li, J., Li, S., Qin, Y., Yang, T., Xiao, Z., Ye, W. and Zhang, Y., 2024. PyOD 2: A Python Library for Outlier Detection with LLM-powered Model Selection. arXiv preprint arXiv:2412.12154.\r\n\r\n.. [#Fang2001Wrap] Fang, K.T. and Ma, C.X., 2001. Wrap-around L2-discrepancy of random sampling, Latin hypercube and uniform designs. Journal of complexity, 17(4), pp.608-624.\r\n\r\n.. [#Goldstein2012Histogram] Goldstein, M. and Dengel, A., 2012. Histogram-based outlier score (hbos): A fast unsupervised anomaly detection algorithm. In *KI-2012: Poster and Demo Track*\\ , pp.59-63.\r\n\r\n.. [#Goodge2022Lunar] Goodge, A., Hooi, B., Ng, S.K. and Ng, W.S., 2022, June. Lunar: Unifying local outlier detection methods via graph neural networks. In Proceedings of the AAAI Conference on Artificial Intelligence.\r\n\r\n.. [#Gopalan2019PIDForest] Gopalan, P., Sharan, V. and Wieder, U., 2019. PIDForest: Anomaly Detection via Partial Identification. In Advances in Neural Information Processing Systems, pp. 15783-15793.\r\n\r\n.. [#Han2022ADBench] Han, S., Hu, X., Huang, H., Jiang, M. and Zhao, Y., 2022. ADBench: Anomaly Detection Benchmark. arXiv preprint arXiv:2206.09426.\r\n\r\n.. [#Hardin2004Outlier] Hardin, J. and Rocke, D.M., 2004. Outlier detection in the multiple cluster setting using the minimum covariance determinant estimator. *Computational Statistics \u0026 Data Analysis*\\ , 44(4), pp.625-638.\r\n\r\n.. [#He2003Discovering] He, Z., Xu, X. and Deng, S., 2003. Discovering cluster-based local outliers. *Pattern Recognition Letters*\\ , 24(9-10), pp.1641-1650.\r\n\r\n.. [#Hoffmann2007Kernel] Hoffmann, H., 2007. Kernel PCA for novelty detection. Pattern recognition, 40(3), pp.863-874.\r\n\r\n.. [#Iglewicz1993How] Iglewicz, B. and Hoaglin, D.C., 1993. How to detect and handle outliers (Vol. 16). Asq Press.\r\n\r\n.. [#Janssens2012Stochastic] Janssens, J.H.M., Huszár, F., Postma, E.O. and van den Herik, H.J., 2012. Stochastic outlier selection. Technical report TiCC TR 2012-001, Tilburg University, Tilburg Center for Cognition and Communication, Tilburg, The Netherlands.\r\n\r\n.. [#Kingma2013Auto] Kingma, D.P. and Welling, M., 2013. Auto-encoding variational bayes. arXiv preprint arXiv:1312.6114.\r\n\r\n.. [#Kriegel2008Angle] Kriegel, H.P. and Zimek, A., 2008, August. Angle-based outlier detection in high-dimensional data. In *KDD '08*\\ , pp. 444-452. ACM.\r\n\r\n.. [#Kriegel2009Outlier] Kriegel, H.P., Kröger, P., Schubert, E. and Zimek, A., 2009, April. Outlier detection in axis-parallel subspaces of high dimensional data. In *Pacific-Asia Conference on Knowledge Discovery and Data Mining*\\ , pp. 831-838. Springer, Berlin, Heidelberg.\r\n\r\n.. [#Latecki2007Outlier] Latecki, L.J., Lazarevic, A. and Pokrajac, D., 2007, July. Outlier detection with kernel density functions. In International Workshop on Machine Learning and Data Mining in Pattern Recognition (pp. 61-75). Springer, Berlin, Heidelberg.\r\n\r\n.. [#Lazarevic2005Feature] Lazarevic, A. and Kumar, V., 2005, August. Feature bagging for outlier detection. In *KDD '05*. 2005.\r\n\r\n.. [#Li2024NLPADBench] Li, Y., Li, J., Xiao, Z., Yang, T., Nian, Y., Hu, X. and Zhao, Y., 2025. NLP-ADBench: NLP Anomaly Detection Benchmark. In *Findings of the Association for Computational Linguistics: EMNLP 2025*.\r\n\r\n.. [#Li2019MADGAN] Li, D., Chen, D., Jin, B., Shi, L., Goh, J. and Ng, S.K., 2019, September. MAD-GAN: Multivariate anomaly detection for time series data with generative adversarial networks. In *International Conference on Artificial Neural Networks* (pp. 703-716). Springer, Cham.\r\n\r\n.. [#Li2020COPOD] Li, Z., Zhao, Y., Botta, N., Ionescu, C. and Hu, X. COPOD: Copula-Based Outlier Detection. *IEEE International Conference on Data Mining (ICDM)*, 2020.\r\n\r\n.. [#Li2021ECOD] Li, Z., Zhao, Y., Hu, X., Botta, N., Ionescu, C. and Chen, H. G. ECOD: Unsupervised Outlier Detection Using Empirical Cumulative Distribution Functions. *IEEE Transactions on Knowledge and Data Engineering (TKDE)*, 2022.\r\n\r\n.. [#Liu2008Isolation] Liu, F.T., Ting, K.M. and Zhou, Z.H., 2008, December. Isolation forest. In *International Conference on Data Mining*\\ , pp. 413-422. IEEE.\r\n\r\n.. [#Liu2019Generative] Liu, Y., Li, Z., Zhou, C., Jiang, Y., Sun, J., Wang, M. and He, X., 2019. Generative adversarial active learning for unsupervised outlier detection. *IEEE Transactions on Knowledge and Data Engineering*.\r\n\r\n.. [#Nguyen2019scalable] Nguyen, M.N. and Vien, N.A., 2019. Scalable and interpretable one-class svms with deep learning and random fourier features. In *Machine Learning and Knowledge Discovery in Databases: European Conference*, ECML PKDD, 2018.\r\n\r\n.. [#Pang2019Deep] Pang, Guansong, Chunhua Shen, and Anton Van Den Hengel. \"Deep anomaly detection with deviation networks.\" In *KDD*, pp. 353-362. 2019.\r\n\r\n.. [#Papadimitriou2003LOCI] Papadimitriou, S., Kitagawa, H., Gibbons, P.B. and Faloutsos, C., 2003, March. LOCI: Fast outlier detection using the local correlation integral. In *ICDE '03*, pp. 315-326. IEEE.\r\n\r\n.. [#Pevny2016Loda] Pevný, T., 2016. Loda: Lightweight on-line detector of anomalies. *Machine Learning*, 102(2), pp.275-304.\r\n\r\n.. [#Perini2020Quantifying] Perini, L., Vercruyssen, V., Davis, J. Quantifying the confidence of anomaly detectors in their example-wise predictions. In *Joint European Conference on Machine Learning and Knowledge Discovery in Databases (ECML-PKDD)*, 2020.\r\n\r\n.. [#Perini2023Rejection] Perini, L., Davis, J. Unsupervised anomaly detection with rejection. In *Proceedings of the Thirty-Seven Conference on Neural Information Processing Systems (NeurIPS)*, 2023.\r\n\r\n.. [#Ramaswamy2000Efficient] Ramaswamy, S., Rastogi, R. and Shim, K., 2000, May. Efficient algorithms for mining outliers from large data sets. *ACM Sigmod Record*\\ , 29(2), pp. 427-438.\r\n\r\n.. [#Rousseeuw1999A] Rousseeuw, P.J. and Driessen, K.V., 1999. A fast algorithm for the minimum covariance determinant estimator. *Technometrics*\\ , 41(3), pp.212-223.\r\n\r\n.. [#Ruff2018Deep] Ruff, L., Vandermeulen, R., Goernitz, N., Deecke, L., Siddiqui, S.A., Binder, A., Müller, E. and Kloft, M., 2018, July. Deep one-class classification. In *International conference on machine learning* (pp. 4393-4402). PMLR.\r\n\r\n.. [#Schlegl2017Unsupervised] Schlegl, T., Seeböck, P., Waldstein, S.M., Schmidt-Erfurth, U. and Langs, G., 2017, June. Unsupervised anomaly detection with generative adversarial networks to guide marker discovery. In International conference on information processing in medical imaging (pp. 146-157). Springer, Cham.\r\n\r\n.. [#Scholkopf2001Estimating] Scholkopf, B., Platt, J.C., Shawe-Taylor, J., Smola, A.J. and Williamson, R.C., 2001. Estimating the support of a high-dimensional distribution. *Neural Computation*, 13(7), pp.1443-1471.\r\n\r\n.. [#Shyu2003A] Shyu, M.L., Chen, S.C., Sarinnapakorn, K. and Chang, L., 2003. A novel anomaly detection scheme based on principal component classifier. *MIAMI UNIV CORAL GABLES FL DEPT OF ELECTRICAL AND COMPUTER ENGINEERING*.\r\n\r\n.. [#Sugiyama2013Rapid] Sugiyama, M. and Borgwardt, K., 2013. Rapid distance-based outlier detection via sampling. Advances in neural information processing systems, 26.\r\n\r\n.. [#Tang2002Enhancing] Tang, J., Chen, Z., Fu, A.W.C. and Cheung, D.W., 2002, May. Enhancing effectiveness of outlier detections for low density patterns. In *Pacific-Asia Conference on Knowledge Discovery and Data Mining*, pp. 535-548. Springer, Berlin, Heidelberg.\r\n\r\n.. [#Wang2020adVAE] Wang, X., Du, Y., Lin, S., Cui, P., Shen, Y. and Yang, Y., 2019. adVAE: A self-adversarial variational autoencoder with Gaussian anomaly prior knowledge for anomaly detection. *Knowledge-Based Systems*.\r\n\r\n.. [#Xu2023Deep] Xu, H., Pang, G., Wang, Y., Wang, Y., 2023. Deep isolation forest for anomaly detection. *IEEE Transactions on Knowledge and Data Engineering*.\r\n\r\n.. [#Yang2024ad] Yang, T., Nian, Y., Li, S., Xu, R., Li, Y., Li, J., Xiao, Z., Hu, X., Rossi, R., Ding, K. and Hu, X., 2024. AD-LLM: Benchmarking Large Language Models for Anomaly Detection. arXiv preprint arXiv:2412.11142.\r\n\r\n.. [#You2017Provable] You, C., Robinson, D.P. and Vidal, R., 2017. Provable self-representation based outlier detection in a union of subspaces. In Proceedings of the IEEE conference on computer vision and pattern recognition.\r\n\r\n.. [#Zenati2018Adversarially] Zenati, H., Romain, M., Foo, C.S., Lecouat, B. and Chandrasekhar, V., 2018, November. Adversarially learned anomaly detection. In 2018 IEEE International conference on data mining (ICDM) (pp. 727-736). IEEE.\r\n\r\n.. [#Zhao2018XGBOD] Zhao, Y. and Hryniewicki, M.K. XGBOD: Improving Supervised Outlier Detection with Unsupervised Representation Learning. *IEEE International Joint Conference on Neural Networks*\\ , 2018.\r\n\r\n.. [#Zhao2019LSCP] Zhao, Y., Nasrullah, Z., Hryniewicki, M.K. and Li, Z., 2019, May. LSCP: Locally selective combination in parallel outlier ensembles. In *Proceedings of the 2019 SIAM International Conference on Data Mining (SDM)*, pp. 585-593. Society for Industrial and Applied Mathematics.\r\n\r\n.. [#Zhao2021SUOD] Zhao, Y., Hu, X., Cheng, C., Wang, C., Wan, C., Wang, W., Yang, J., Bai, H., Li, Z., Xiao, C., Wang, Y., Qiao, Z., Sun, J. and Akoglu, L. (2021). SUOD: Accelerating Large-scale Unsupervised Heterogeneous Outlier Detection. *Conference on Machine Learning and Systems (MLSys)*.\r\n\r\n.. [#Boniol2021SAND] Boniol, P., Paparrizos, J., Palpanas, T. and Franklin, M.J., 2021. SAND: Streaming Subsequence Anomaly Detection. *Proceedings of the VLDB Endowment*, 14(10), pp.1717-1729.\r\n\r\n.. [#Malhotra2015Long] Malhotra, P., Vig, L., Shroff, G. and Agarwal, P., 2015. Long Short Term Memory Networks for Anomaly Detection in Time Series. In *European Symposium on Artificial Neural Networks (ESANN)*.\r\n\r\n.. [#Paparrizos2015KShape] Paparrizos, J. and Gravano, L., 2015. k-Shape: Efficient and Accurate Clustering of Time Series. In *Proceedings of the 2015 ACM SIGMOD International Conference on Management of Data*, pp.1855-1870.\r\n\r\n.. [#Ren2019Time] Ren, H., Xu, B., Wang, Y., Yi, C., Huang, C., Kou, X., Xing, T., Yang, M., Tong, J. and Zhang, Q., 2019. Time-Series Anomaly Detection Service at Microsoft. In *Proceedings of the 25th ACM SIGKDD International Conference on Knowledge Discovery \u0026 Data Mining*, pp.3009-3017.\r\n\r\n.. [#Xu2022Anomaly] Xu, J., Wu, H., Wang, J. and Long, M., 2022. Anomaly Transformer: Time Series Anomaly Detection with Association Discrepancy. In *International Conference on Learning Representations (ICLR)*.\r\n\r\n.. [#Yeh2016Matrix] Yeh, C.C.M., Zhu, Y., Ulanova, L., Begum, N., Ding, Y., Dau, H.A., Silva, D.F., Mueen, A. and Keogh, E., 2016. Matrix Profile I: All Pairs Similarity Joins for Time Series Subsequences. In *2016 IEEE 16th International Conference on Data Mining (ICDM)*, pp.1317-1322.\r\n\r\n.. [#Ding2019DOMINANT] Ding, K., Li, J., Bhanushali, R. and Liu, H., 2019. Deep Anomaly Detection on Attributed Networks. In *Proceedings of the 2019 SIAM International Conference on Data Mining*, pp.594-602. SIAM.\r\n\r\n.. [#Liu2022CoLA] Liu, Y., Li, Z., Pan, S., Gool, T., Xiang, T. and Gong, B., 2022. Anomaly Detection on Attributed Networks via Contrastive Self-Supervised Learning. In *Proceedings of the ACM Web Conference 2022*, pp.2137-2147.\r\n\r\n.. [#Xu2022CONAD] Xu, Z., Huang, X., Zhao, Y., Dong, Y. and Li, J., 2022. Contrastive Attributed Network Anomaly Detection with Data Augmentation. In *Pacific-Asia Conference on Knowledge Discovery and Data Mining*, pp.444-457. Springer.\r\n\r\n.. [#Fan2020AnomalyDAE] Fan, H., Zhang, F. and Li, Z., 2020. AnomalyDAE: Dual Autoencoder for Anomaly Detection on Attributed Networks. In *Proceedings of the 29th ACM International Conference on Information and Knowledge Management*, pp.747-756.\r\n\r\n.. [#Yuan2021GUIDE] Yuan, X., Zhou, N., Yu, S., Huang, H., Chen, Z. and Xia, F., 2021. Higher-Order Structure Based Anomaly Detection on Attributed Networks. In *2021 IEEE International Conference on Big Data*, pp.2691-2700. IEEE.\r\n\r\n.. [#Li2017Radar] Li, J., Dani, H., Hu, X. and Liu, H., 2017. Radar: Residual Analysis for Anomaly Detection in Attributed Networks. In *Proceedings of the Twenty-Sixth International Joint Conference on Artificial Intelligence*, pp.2152-2158.\r\n\r\n.. [#Peng2018ANOMALOUS] Peng, Z., Luo, M., Li, J., Liu, H. and Zheng, Q., 2018. ANOMALOUS: A Joint Modeling Approach for Anomaly Detection on Attributed Networks. In *Proceedings of the Twenty-Seventh International Joint Conference on Artificial Intelligence*, pp.3529-3535.\r\n\r\n.. [#Xu2007SCAN] Xu, X., Yuruk, N., Feng, Z. and Schweiger, T.A.J., 2007. SCAN: A Structural Clustering Algorithm for Networks. In *Proceedings of the 13th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining*, pp.824-833.\r\n\r\n.. [#Liu2024TSB] Liu, Q., Boniol, P., Palpanas, T. and Paparrizos, J., 2024. TSB-AD: Towards A Reliable Time-Series Anomaly Detection Benchmark. In *Advances in Neural Information Processing Systems (NeurIPS)*.\r\n\r\n.. [#Liu2022BOND] Liu, K., Dou, Y., Zhao, Y., Ding, X., Hu, X., Zhang, R., Ding, K., Chen, C., Peng, H., Shu, K., Sun, L., Li, J., Chen, G.H., Jia, Z. and Yu, P.S., 2022. BOND: Benchmarking Unsupervised Outlier Node Detection on Static Attributed Graphs. In *Advances in Neural Information Processing Systems (NeurIPS)*.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyzhao062%2Fpyod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyzhao062%2Fpyod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyzhao062%2Fpyod/lists"}