PyOD

Also known as: Python Outlier Detection

On this page 7

PyOD, short for Python Outlier Detection, is an open-source Python library that provides dozens of outlier and anomaly detection algorithms behind a single, consistent interface modeled on scikit-learn. In anomaly detection practice, it is one of the most widely used toolkits for tabular, multivariate data, covering classical statistical methods, proximity-based detectors, ensembles and neural network models.

The library was started in 2017 by an academic research group and described in a peer-reviewed paper in the Journal of Machine Learning Research in 2019. Its value lies less in any single algorithm than in making many detectors interchangeable, so that a team can compare methods on the same data with only a few changed lines of code.

How the PyOD detector interface works

Every PyOD model inherits from a common base detector class and follows the same lifecycle. The user creates a detector, calls fit on training data, and then reads anomaly scores and binary labels either for the training set or for new samples. Higher scores always mean more anomalous, which makes scores from different detectors comparable after normalization.

ElementWhat it returnsTypical use
fit(X)The fitted detectorLearn the normal data profile
decision_scores_Raw scores of training samplesRank training records
labels_0 for inliers, 1 for outliersFlag training records
decision_function(X)Raw scores for new samplesScore incoming data
predict(X)Binary labels for new samplesTrigger alerts
predict_proba(X)Outlier probabilityCalibrated risk ranking
threshold_Score cutoff learned in fitAudit the decision boundary
Core methods and attributes of a PyOD detector

The contamination parameter, which defaults to 0.1, states the expected share of outliers in the training data. PyOD uses it to set threshold_ at the matching percentile of training scores, so the binary labels depend directly on this assumption, while the raw scores do not.

Algorithm families available in PyOD

PyOD groups its detectors into several families, each with a different idea of what makes a point unusual. Knowing the family helps predict how a detector behaves on high-dimensional, clustered or noisy data.

FamilyRepresentative modelsCore idea
Probabilistic and statisticalECOD, COPOD, HBOSLow probability under estimated distributions
Linear modelsPCA, MCD, OCSVMLarge deviation from a fitted subspace or boundary
Proximity-basedKNN, LOF, CBLOFLarge distance or low local density
Ensemble-basedIForest, Feature bagging, LODAEasy isolation or disagreement across models
Neural networksAutoEncoder, VAE, Deep SVDDHigh reconstruction error or distance in latent space
Graph-basedLUNARLearned aggregation over nearest-neighbor graphs
Main detector families and representative models

ECOD and COPOD deserve special mention because they are parameter-free and fast, which makes them strong first baselines. Isolation forest remains a robust general choice on large tables, while local outlier factor suits data where density varies between regions.

Model combination and scaling features

Single detectors are often unstable, so PyOD includes score combination functions that merge several models into one decision. Scores are first standardized so that detectors with different scales contribute fairly, and then combined by averaging, maximization, or the hybrid schemes average of maximum and maximum of average.

For large workloads, the companion framework SUOD trains many heterogeneous detectors in parallel and can approximate costly models with faster supervised regressors. Version 2 of the library, released in 2024, moved deep learning models to a unified PyTorch backend and added automated model selection that recommends detectors from a description of the dataset.

Choosing a PyOD detector for a task

No detector wins on every dataset, which large public benchmarks of unsupervised anomaly detection have shown repeatedly. The practical approach is to start with fast baselines, measure them against any available labels, and move to complex models only when they deliver a clear and repeatable gain.

SituationSuggested starting detectorReason
No labels, first look at dataECOD or IForestFast, few parameters, robust
Clusters of different densityLOF or KNNMeasures local rather than global rarity
Hundreds of featuresIForest or AutoEncoderScales better than distance methods
Clean training set of normal dataOCSVM or Deep SVDDLearns a tight normal boundary
Unstable results across methodsAveraged ensembleReduces variance of single detectors
Decision guide for common situations

Feature scaling matters for distance and kernel methods, so inputs should be standardized before fitting KNN, LOF or OCSVM. Tree-based isolation forest is largely insensitive to scaling.

Limitations and common misuse

PyOD is designed mainly for static tabular data. It is not a time series anomaly detection library, so seasonality, trends and temporal context must be engineered into features beforehand or handled with specialized tools. It also does not include production features such as streaming ingestion, alert routing or drift monitoring.

  • Treating contamination as known leads to fixed alert volumes that do not reflect the real anomaly rate.
  • Evaluating on training scores only hides overfitting, especially for neural detectors.
  • Comparing raw scores across models without standardization produces misleading ensembles.
  • Ignoring categorical encoding distorts distances when one-hot columns dominate numeric features.

Unsupervised scores also need human validation. A high score means a record is unusual under the chosen definition, not that it is fraud or a fault, so domain review and anomaly explanation remain essential.

A plain-language summary

PyOD is a toolbox for finding odd records in a table of data. Each tool uses a different way to spot what does not fit. One looks for points far from their neighbors. Another checks how easily a point can be separated from the rest.

All tools in the box work the same way. You give data, and each tool returns a score for every record. A higher score means more unusual. This makes it easy to try several tools and keep the one that works best.

An example from practice

A manufacturing plant collects 40 sensor readings per minute from each of 120 packaging machines, including motor current, vibration and temperature. Engineers have almost no labeled failures, so they need an unsupervised approach to find early warning signs.

A data analyst builds hourly feature summaries and fits three PyOD detectors, ECOD, IForest and an AutoEncoder, with contamination set to 0.02. The standardized scores are averaged into one ensemble. During a two-month pilot, the top 1 percent of flagged hours includes seven of the nine recorded breakdowns, each flagged between six and 30 hours in advance. Maintenance staff review the alerts weekly, and the plant moves the model into its regular monitoring routine with a quarterly retraining schedule.