PyOD (Python Outlier Detection) is a Python library for finding outliers in numeric tabular data. It brings traditional machine-learning and deep-learning detectors under a consistent API, making it easier to try different approaches rather than rely on one detector. section 6.0
A typical detection workflow is:
- Create a detector and call fit() on training data. For training rows, read numeric outlier scores from decision_scores_. section 6.1
- For separate test rows, use decision_function() for scores or predict() for binary labels. predict_proba() scales scores to a 0–1 range by default; its outputs are not true probabilities. section 6.1
- Check detector-specific hyperparameters even when the defaults run successfully: a setting may be unsuitable for the data or detection goal. section 6.1
Listing 6.1 Basic example using PyOD with the KNN detector
from pyod.models.knn import KNN clf = KNN() clf.fit(data) scores = clf.decision_scores_
The KNN listing shows the minimal pattern: instantiate a detector, fit it, and retrieve training scores. section 6.1
Scores need interpretation. In a synthetic KNN example, points well outside the main cluster score higher than points near its edge; the edge points are less clearly separated from inliers. Comparing scores with known labels and their distribution is more informative than treating every predicted label as an equally clear case. section 6.1
PyOD also supplies generate_data() for initial experiments, with labeled outliers and separate training and test rows. Its simple generated data is not meant to resemble an arbitrary real dataset; realistic synthetic data is preferable for tuning and testing a detection system. Deep-learning detectors use the same API, but require the relevant TensorFlow/Keras or PyTorch installation. section 11.2.1 section 16.2
