Supervised anomaly detection

On this page 7

Supervised anomaly detection is the approach to anomaly detection in which a model learns from training data labeled as normal or anomalous and then classifies new observations into those classes or assigns them an anomaly probability. It treats the task as binary classification under extreme class imbalance, because anomalies typically make up well under one percent of the data.

Within artificial intelligence, the supervised approach is the most accurate choice when reliable labels for past anomalies exist and future anomalies resemble them, as in card fraud, insurance claims or recurring machine faults. Its main weakness is the mirror image of that strength: it is weak at recognizing anomaly types it has never seen, which is where unsupervised and semi-supervised methods take over.

How supervised anomaly detection learns from labels

A supervised anomaly detector is trained on pairs of feature vectors and labels, usually 0 for normal and 1 for anomalous. The model learns a decision boundary between the two classes and, at inference time, outputs a score that is compared with a threshold chosen to meet operational targets such as a maximum false alarm rate.

The standard pipeline has four stages: label collection from investigations, chargebacks or maintenance records; feature engineering, often with aggregates over time windows; model training with imbalance handling; and threshold calibration on a validation set whose class ratio matches production. Labels usually arrive with a delay, so the training set lags behind the current anomaly patterns.

Tree ensembles such as gradient boosting dominate tabular use cases because they handle mixed feature types, missing values and nonlinear interactions with little preprocessing. For images, logs and sequences, deep neural classifiers are used instead, often pretrained on large unlabeled corpora and then fine-tuned on the scarce anomaly labels. Whatever the model, its output is best treated as a ranking score for prioritization rather than a final verdict.

Supervised, semi-supervised and unsupervised approaches

The three learning settings differ mainly in which labels are available, and that difference decides what kinds of anomalies each can catch. The table contrasts them.

SettingTraining labelsDetects novel anomaliesTypical methods
SupervisedNormal and anomalous examplesPoorlyGradient boosting, random forests, neural classifiers
Semi-supervisedNormal examples only, or few anomaliesReasonably wellOne-class SVM, autoencoders, Deep SVDD
UnsupervisedNo labelsWell, if anomalies are rare and distinctIsolation forest, local outlier factor, HBOS
Learning settings in anomaly detection

In practice these settings are often combined in one system. An unsupervised detector surfaces unusual cases for analysts, their verdicts become labels, and a supervised model trained on those labels handles known anomaly patterns with higher precision. The unsupervised score can also serve as an extra input feature for the supervised model.

Handling extreme class imbalance

Class imbalance is the central technical problem of supervised anomaly detection. With a ratio of 1 anomaly per 1,000 normal cases, a model that always predicts normal reaches 99.9 percent accuracy while catching nothing, so training and evaluation must be adapted. The table lists the main techniques.

TechniqueHow it worksMain risk
Class weightingRaises the loss penalty for missed anomaliesOverconfident scores without recalibration
Random undersamplingRemoves part of the normal majorityDiscards useful normal variety
Oversampling and SMOTEDuplicates or interpolates anomaliesSynthetic points that do not exist in reality
Focal lossDown-weights easy, well-classified examplesExtra hyperparameters to tune
Threshold tuningMoves the cut-off on the score scaleThreshold drifts as data changes
Techniques for imbalanced anomaly data

Resampling changes the apparent class ratio, so the predicted probabilities no longer reflect real frequencies. When downstream decisions depend on calibrated probabilities, teams apply Platt scaling or isotonic regression on data with the true production ratio.

Evaluating a supervised anomaly detector

Evaluation must use metrics that remain informative when positives are rare. Precision-recall metrics are preferred over accuracy and often over ROC AUC, because ROC curves can look excellent while the false positives still overwhelm the true alerts. The table summarizes the usual measures.

MetricWhat it measuresWhen to use it
PrecisionShare of alerts that are real anomaliesWhen analyst capacity is limited
RecallShare of anomalies that are caughtWhen misses are costly
PR AUCPrecision across all recall levelsComparing models on rare classes
ROC AUCRanking quality across thresholdsSecondary check, optimistic under imbalance
Precision at kHit rate among the top k alertsFixed daily review budgets
Expected costWeighted cost of misses and false alarmsSetting the operating threshold
Metrics for imbalanced anomaly detection

Validation must also respect time. A time-based split, training on earlier months and testing on later ones, reveals degradation that a random split hides, because random splits leak future anomaly patterns into training and overstate real-world performance.

Limitations and common mistakes

Supervised detectors fail in predictable ways, most of which trace back to the labels rather than the algorithm. Recognizing these patterns early prevents costly false confidence.

  • Blindness to novel anomalies: new fraud schemes or unseen fault modes receive low scores because no similar label exists.
  • Label noise and selection bias: only investigated cases get labels, so the model learns what investigators chose to check.
  • Concept drift: adversaries adapt, so performance decays and regular retraining is mandatory.
  • Feedback loops: blocked transactions never reveal their true outcome, which distorts future training data.
  • Leaky features: variables recorded after the event, such as a chargeback flag, inflate offline scores.

A non-technical view

Think of a bank clerk who has seen thousands of forged checks. Over time, the clerk learns what fakes look like. Supervised anomaly detection works the same way. A computer studies past examples marked as normal or suspicious and learns to tell them apart.

This works very well for familiar tricks. The catch is that the computer only knows what it was shown. A completely new kind of forgery may slip through. For that reason, companies usually pair it with other methods that look for anything simply unusual.

A concrete example

An online payment processor handles about 2 million card transactions per day, of which roughly 0.1 percent are later confirmed as fraud through chargebacks. The data science team trains a gradient-boosted tree model on 18 months of labeled transactions, using features such as spending velocity over the last hour, distance from the usual merchant locations and device fingerprint changes.

Because fraud analysts can review only 1,500 cases per day, the team sets the threshold by precision at 1,500 alerts rather than by accuracy. Evaluated on the most recent three months, the model catches about 70 percent of fraud value at that alert volume. An isolation forest runs alongside it to flag unusual activity the classifier has never seen, and confirmed cases from both systems feed the monthly retraining cycle.