Registry / ai-ml / pyod
library3.6.5pypypi✓ verified 25d ago

PyOD is a comprehensive and scalable Python library for outlier detection (anomaly detection), offering over 50 detection models. It provides a unified API, making it easy to use and compare various algorithms. The library is currently at version 2.1.0, with frequent minor releases addressing compatibility and adding new features, including recent advancements in multi-modal anomaly detection using foundation model embeddings.

pip install pyod
INSTALL
IMPORT
SIG · PYOD
P
pyod
ai-mlpythonv3.6.5
Install
17.1s avg
Import
4555ms
Disk
567MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.6.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 17.1s · import 4.555s · 556MB
567MB installed
● package 567MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

KNN
from pyod.models.knn import KNN
generate_data
from pyod.utils.data import generate_data
EmbeddingOD
from pyod.models.embedding_od import EmbeddingOD
New in v2.1.0 for multi-modal anomaly detection, requires additional dependencies like `sentence-transformers`.

This quickstart demonstrates how to generate synthetic data and use the k-Nearest Neighbors (KNN) algorithm from PyOD to detect outliers. It shows the basic steps of initialization, fitting the model, and retrieving binary outlier labels and raw anomaly scores.

from pyod.models.knn import KNN from pyod.utils.data import generate_data import numpy as np # Generate random data with 20% outliers X_train, y_train = generate_data(n_train=200, n_features=2, n_outliers=20, random_state=42) # Initialize and train a kNN detector clf = KNN(contamination=0.1) # Set contamination based on expected outlier ratio clf.fit(X_train) # Get the prediction labels (0: inliers, 1: outliers) y_train_pred = clf.labels_ # Get the raw outlier scores y_train_scores = clf.decision_scores_ print(f"Number of training samples: {len(X_train)}") print(f"Number of predicted outliers: {np.count_nonzero(y_train_pred)}")
Debug
Known issues
breakingPyOD removed all TensorFlow and Keras code, migrating deep learning models entirely to PyTorch.
fix
If you relied on TensorFlow-based models, either pin your PyOD version to <2.0.2 or refactor your code to use PyTorch-based models available in PyOD v2.0.2 and later.
affects: <2.0.2
breakingDefault parameters for some models, notably VAE, have changed (e.g., output activation for VAE to `identity`).
fix
Existing VAE models trained with older PyOD versions may produce different results. Consider re-training models or explicitly setting parameters like `output_activation` to maintain backward compatibility if migrating.
affects: <2.0.7
gotchaThe `contamination` parameter is crucial and can significantly impact detection results and thresholds, especially when not set accurately.
fix
Understand that `contamination` is the proportion of outliers in the data. It's used for thresholding (`predict` and `labels_`). If unknown, careful validation or methods like `predict_proba` might be needed. Setting it too high or too low can lead to misclassifications.
affects: All versions
gotchaPyOD frequently updates its internal dependencies and sometimes makes adjustments for `scikit-learn` breaking changes.
fix
It's generally recommended to keep PyOD updated, or ensure compatibility between your `pyod` and `scikit-learn` versions to avoid unexpected behavior, especially after major `scikit-learn` releases.
affects: All versions, particularly pre-2.0.6 with newer scikit-learn
gotchaThe new `EmbeddingOD` framework (v2.1.0+) requires additional, potentially large, third-party libraries (e.g., `sentence-transformers`, `openai`, `transformers`) that are not installed by default.
fix
Install the necessary optional dependencies using `pip install pyod[text]` or `pip install pyod[image]` or individual packages as required by your chosen embedding model (e.g., `pip install sentence-transformers`).
affects: 2.1.0+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pyod'
The PyOD library is not installed in the current Python environment.
fix
pip install pyod
ImportError: cannot import name 'LOF' from 'pyod.models.lof'
PyOD model classes (e.g., LOF) are typically exposed directly under the 'pyod.models' module, not nested within submodules.
fix
from pyod.models import LOF
ValueError: Expected 2D array, got 1D array instead:
PyOD models, like most scikit-learn estimators, expect input data (X) to be a 2D array (n_samples, n_features), but a 1D array was provided.
fix
Reshape your input data to a 2D array, for example, using 'X.reshape(-1, 1)' for a single feature.
AttributeError: 'LOF' object has no attribute 'decision_function'
You are attempting to access a non-existent or incorrectly named attribute to retrieve anomaly scores after fitting a PyOD model.
fix
Use 'model.decision_scores_' to get raw anomaly scores or 'model.labels_' for binary outlier labels after fitting.
ValueError: Expected 2D array, got 1D array instead: array=[...]. Reshape your data using X.reshape(-1, 1) if it contains a single feature or X.reshape(1, -1) if it contains a single sample.
PyOD models, like scikit-learn estimators, expect input data to be a 2D array (n_samples, n_features), but a 1D array (e.g., a single feature or a single sample) was provided.
fix
Reshape your 1D input data `X` into a 2D array, for example, `X_train_reshaped = X_train.reshape(-1, 1)` if it's a feature array, or convert a pandas Series using `X_train_reshaped = X_train.values.reshape(-1, 1)`.
Upgrade
Version history
3.6.5latest on PyPI · released Aug 17, 2026
Audit
Dependencies
scikit-learnrequiredCore machine learning utilities and base estimators.
torchrequiredRequired for deep learning-based models, replacing TensorFlow since v2.0.2.
sentence-transformersoptionalOptional, required for text embeddings in EmbeddingOD (v2.1.0+).
transformersoptionalOptional, for HuggingFace model embeddings in EmbeddingOD (v2.1.0+).
openaioptionalOptional, for OpenAI model embeddings in EmbeddingOD (v2.1.0+).
Agent activity
32 hits · last 30 days
node
18
OpenAI (training)
1
Resources
pyod — pip install pyod · libregistry