Semi-supervised anomaly detection

On this page 7

Semi-supervised anomaly detection is the anomaly detection setting in which a model is trained on data known to be normal, with few or no labeled anomalies, and then scores new observations by how strongly they deviate from the learned notion of normality. It sits between unsupervised anomaly detection, which assumes no labels at all, and supervised anomaly detection, which needs labeled examples of both classes.

The approach fits the reality of most industrial and security data: normal behavior is abundant and easy to collect, while anomalies are rare, diverse and often unknown in advance. Because the model never needs to see a specific failure type, it can in principle detect previously unseen anomalies. The terminology is not fully standardized: some authors call this setting novelty detection or one-class classification, while others use the term for methods that combine many unlabeled samples with a small set of labeled anomalies.

How semi-supervised anomaly detection works

The workflow has three stages. First, a clean training set of normal observations is assembled, for example sensor readings from machines confirmed to be healthy. Second, a model learns a compact description of that data, such as a density, a boundary or a reconstruction mapping. Third, each new observation receives an anomaly score, and a decision threshold converts the score into an alert.

The scoring principle varies by model family, but the logic is always the same: normal data fits the model well, and anomalous data fits it poorly. A high reconstruction error, a low likelihood or a large distance from a learned center all signal deviation.

The table below shows how the labeling assumption distinguishes the three main anomaly detection settings.

SettingTraining dataMain strengthMain weakness
SupervisedLabeled normal and anomalousHigh accuracy on known anomaly typesMisses novel anomalies
Semi-supervisedNormal only, or few labeled anomaliesDetects unseen deviationsNeeds clean normal data
UnsupervisedUnlabeled mixtureNo labeling effortSensitive to contamination rate
Label assumptions in anomaly detection settings

Main model families

Semi-supervised detectors fall into four broad families: boundary methods, density methods, reconstruction methods and distance methods. The choice depends on data type, dimensionality and the volume of normal data available.

FamilyRepresentative methodsAnomaly scoreTypical data
BoundaryOne-class SVM, support vector data descriptionDistance outside learned boundaryTabular, moderate dimensions
Deep boundaryDeep SVDDDistance from hypersphere centerImages, embeddings
DensityGaussian mixture, elliptic envelopeNegative log-likelihood or Mahalanobis distanceLow-dimensional continuous data
ReconstructionAutoencoders, variational autoencodersReconstruction errorImages, multivariate time series
Distance or memory bankk-NN on embeddings, PatchCoreDistance to nearest normal featureVisual inspection
Common semi-supervised anomaly detection methods

In visual inspection, methods such as PatchCore and PaDiM use features from a pretrained network and compare image patches with a memory of normal patches. This combination of pretrained features and normal-only training currently gives strong results on benchmarks such as MVTec AD.

Using a small set of labeled anomalies

In the broader sense of the term, semi-supervised detection also covers models that exploit a handful of labeled anomalies alongside plentiful unlabeled or normal data. Methods such as Deep SAD extend Deep SVDD so that labeled anomalies are pushed away from the normal center while normal points are pulled toward it.

Even a few dozen confirmed anomalies can sharpen the decision boundary and reduce false alarms, but they also carry a risk: the model may overfit to known anomaly types and become less sensitive to new ones. Practitioners therefore keep the normal-data objective dominant and treat labeled anomalies as guidance rather than as a full second class.

Setting thresholds and measuring performance

Because training data contains few or no anomalies, the threshold is usually set from the score distribution of held-out normal data, for example at the 99th or 99.9th percentile. This choice directly fixes the expected false positive rate on normal traffic, which is often the constraint operators care about most.

Evaluation requires at least some labeled anomalies, even if training does not. Accuracy is misleading under heavy class imbalance, so teams rely on threshold-independent metrics and operational measures.

MetricWhat it measuresWhen to prefer it
AUROCRanking quality across all thresholdsBalanced comparison of models
AUPRCPrecision and recall under imbalanceAnomalies below about 1 percent
Precision at kShare of true anomalies in top alertsFixed analyst review capacity
False positive rateShare of normal data flaggedAlert fatigue is the main concern
Detection delayTime from onset to alertStreaming and time series data
Evaluation metrics for semi-supervised detectors

Limitations and common mistakes

The central assumption, that the training data is purely normal, is rarely perfect. Undetected anomalies in the training set teach the model that they are normal, a problem known as training contamination. Robust losses and data cleaning reduce the effect but do not remove it.

  • Concept drift: normal behavior changes over time, so models need periodic retraining on recent normal data.
  • Incomplete normality: rare but legitimate operating modes missing from training produce false alarms.
  • Overgeneralizing autoencoders: a powerful model may reconstruct anomalies well and miss them.
  • Threshold set on training data: scores on seen data are optimistic; use a held-out normal set.
  • Unexplained alerts: without anomaly explanation, operators cannot act on a bare score.

In simple terms

Think of a night guard who has walked the same building for months. The guard has never been told what a burglary looks like. But the guard knows what a normal night looks like. Any unusual sound or open door stands out at once.

Semi-supervised anomaly detection works the same way. The computer studies plenty of normal examples. It then raises a flag when something does not match. It does not need a list of every possible problem.

A practical example

A manufacturer of injection-molded parts installs cameras on a production line that makes about 40,000 parts per day. Defects such as cracks, burns and short shots occur in well under 1 percent of parts, and new defect types appear whenever a mold or material changes, so collecting labeled defect images for every case is impractical.

The quality team trains a PatchCore-style detector on 2,000 images of parts confirmed as good. They set the threshold at the 99.5th percentile of scores on a separate set of good parts, which limits false rejects to roughly 0.5 percent. In the first month, the system flags a previously unseen flow-line defect caused by a worn nozzle. Inspectors review flagged parts, and the team adds new normal variants to the training set each quarter to keep pace with process drift.