- Introduced by
- Ruff, L. et al.; Zong, B. et al.
- Year
- 2018–2020
- Type
- Semi-supervised deep anomaly detection
- Family
- Machine learning
What does it do?
Semi-supervised Autoencoder Anomaly Detection trains a neural autoencoder mainly on unlabeled data assumed to be normal, then uses a small set of labeled anomalies to shape the decision rule.
Samples that the trained network reconstructs poorly, measured by a reconstruction-error score, are flagged as anomalous. The method sits between purely unsupervised autoencoders and fully supervised classifiers, and is used when labels are scarce but some confirmed anomalies exist.
The intuition behind the method
An autoencoder learns to compress and reconstruct the data it is trained on. Inputs that resemble the training data are reconstructed closely, while unfamiliar inputs leave a larger residual, so the residual serves as an anomaly score. A purely unsupervised autoencoder learns only what normal data look like and has no labeled anomalies against which to check its decisions, so its threshold usually depends on assumptions such as an expected contamination rate or domain knowledge. The semi-supervised variant uses a small set of labeled anomalies during training or threshold setting, so the model is shaped by known abnormal cases as well as normal ones. This only helps if the labeled anomalies are representative; a small set covering a single failure type will shape the decision boundary mainly for that type.
History
Autoencoder-based anomaly detection spread with the wider adoption of deep learning. Zong et al. (ICLR 2018) combined an autoencoder with a Gaussian mixture model for unsupervised anomaly detection, so that work belongs to the unsupervised line rather than the semi-supervised one. Ruff et al. (ICLR 2020) introduced deep semi-supervised anomaly detection, which uses labeled anomalies alongside unlabeled data; its scoring relies on a hypersphere-style objective rather than on a reconstruction-error score. The reconstruction-error formulation described on this page is therefore best read as an adaptation of the autoencoder approach to the semi-supervised setting, not as a method attributed to either paper.
When to use it
Choose this method when you have a large pool of unlabeled data that is predominantly normal, a small set of reliable confirmed anomalies, and unsupervised detectors produce too many false alarms. It suits high-dimensional or non-linear inputs such as sensor signals, network traffic, or images, where kernel-based detectors such as one-class SVM may need different tuning; benchmark the candidates on your own data (see the FAQ). Do not use it when no labeled anomalies are available; unsupervised autoencoders are the appropriate choice then. Also do not use it when enough labels exist for a standard supervised classifier. Avoid it on very small datasets, where a deep network is likely to overfit and a simpler detector is a safer starting point.
Limitations and considerations
- Requires careful partitioning: if the unlabeled pool contains many anomalies, pre-training is corrupted and performance can degrade noticeably.
- Deep autoencoders are compute-intensive to train and tune compared to shallow methods.
- Interpretability is limited; the reconstruction-error signal does not explain which features caused the anomaly.
- Sensitive to the choice of architecture depth, latent dimension, and loss weighting between the unsupervised and supervised objectives.
- Threshold selection is non-trivial and must be validated on held-out labeled data to avoid arbitrary cut-offs.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Uses a large unlabeled normal pool together with a small set of labeled anomalies, so labels are needed only for the abnormal cases.
- Can model non-linear structure in high-dimensional inputs, because the network learns the representation rather than relying on a fixed kernel choice.
- The reconstruction-error score is continuous, so the operating threshold can be moved along the precision-recall curve to match the cost of false alarms.
- Pretraining on normal data gives the model a prior over normal structure, which can help when labeled anomalies are few.
- The encoder and decoder can be built from convolutional, recurrent, or transformer layers to suit images, time series, or text.
Applications
- Industrial fault and defect detection on sensor or telemetry streams where faulty events are rare but documented.
- Network intrusion and cybersecurity anomaly detection with known attack signatures as labeled seeds.
- Medical imaging or clinical data screening where confirmed pathological cases are scarce.
- Financial fraud detection combining abundant normal transactions with a small set of confirmed fraudulent ones.
- Predictive maintenance pipelines where historical failure records serve as labeled anomaly examples.
How it works
How it works
The available data are split into a large pool of unlabeled samples, assumed to be mostly normal, and a small curated set of labeled anomalies. The labeled anomalies are needed for two purposes, fine-tuning and threshold selection, so part of them should be held out for the second use.
An encoder-decoder network is trained on the unlabeled pool to minimise reconstruction loss, producing a latent representation of the dominant normal patterns. No labels are used in this phase, so any anomalies hidden in the pool are learned as if they were normal.
The pretrained network is then updated using the labeled anomalies. The objective used on this page is a combined loss: the mean reconstruction error over the unlabeled pool, plus a weighted hinge penalty on the labeled anomalies that pushes their reconstruction error above a margin m. Written schematically, L = mean over unlabeled x of ||x - x_hat||^2 + lambda * mean over labeled anomalies a of max(0, m - ||a - a_hat||^2). The weight lambda and the margin m are hyperparameters chosen on validation data, not fixed values. Other objectives are possible, such as a classification head, a hypersphere-style or contrastive loss, or a different penalty on anomaly reconstructions. The chosen objective changes what the decision boundary captures, so it should be stated explicitly when results are reported.
Each sample is passed through the trained autoencoder and scored by the squared Euclidean norm of its residual, s(x) = ||x - x_hat||^2, where x_hat is the reconstruction. This is a sum over input dimensions, not a per-feature mean; the two differ by a constant factor for a fixed input dimension, so the definition used should be stated. Some implementations also add a latent-space distance from a normal-class centroid.
Formula
s(x) = \|x - \hat{x}\|^2A threshold on the score converts it into normal or anomaly labels. It should be chosen on labeled data not used for training. A workable procedure is as follows. First, keep a labeled validation split that is never used for fine-tuning. Second, compute scores on that split. Third, select the threshold either at a target false-positive rate or at the point on the precision-recall curve that maximises an F-beta score, with beta reflecting the relative cost of false alarms and missed anomalies. Fourth, freeze the threshold and evaluate once on a separate test split. The threshold sets the precision-recall trade-off, so it should reflect the operational cost of each type of error.
Common pitfalls
- Contaminating the unlabeled pre-training pool with undetected anomalies, which undermines the normal-data representation.
- Treating reconstruction error as a calibrated probability without proper threshold calibration against labeled examples.
- Evaluating on a single split in which the few anomalies are not spread across training and test sets, producing overoptimistic estimates; use stratified splits or repeated resampling and report the variability.
- Selecting the latent dimension without experimentation: a latent space that is too small loses information about normal data, while one that is too large lets the autoencoder reconstruct anomalies about as well as normal samples.
- Ignoring class imbalance when computing evaluation metrics; accuracy is uninformative when anomalies are rare, so use AUROC and average precision instead.
Frequently asked questions
How many labeled anomalies are needed?
There is no fixed minimum. The method can work with only a few confirmed anomalies, but results depend on how well those anomalies cover the main types of abnormal behaviour in the domain. Check sensitivity by training with different subsets of the labeled set.
What if my unlabeled pool contains hidden anomalies?
Unlabeled contamination is the biggest failure mode. Apply a preliminary unsupervised filter, such as an isolation forest, to remove obvious outliers from the pre-training pool before fine-tuning. This filter can also remove rare but legitimate normal samples, so check that it does not discard them, for example by inspecting the removed samples or by comparing downstream results with and without the filter.
How do I choose the reconstruction-error threshold?
Use your labeled anomaly set and a precision-recall curve to pick a threshold matching your operational tolerance for false positives and false negatives. Never choose the threshold on the same data used to train the model.
Is this better than a one-class SVM or isolation forest?
No general ranking holds. Whether a semi-supervised autoencoder outperforms one-class SVM or isolation forest depends on dimensionality, the amount of labeled data, and the sample size. Benchmark the candidates on held-out data from your own domain; simpler methods are a reasonable baseline, particularly for low-dimensional tabular data.
What evaluation metrics should I report?
Report AUROC and average precision (area under the precision-recall curve) on a held-out test set that preserves the true anomaly prevalence. Accuracy and F1 at a fixed threshold should be secondary metrics, with the threshold justified.
Related methods
Sources
Ruff, L., Vandermeulen, R. A., Franks, B. J., Müller, K.-R., & Kloft, M. (2020). Deep Semi-Supervised Anomaly Detection. In International Conference on Learning Representations (ICLR 2020).
Open publication referenceZong, B., Song, Q., Min, M. R., Cheng, W., Lumezanu, C., Cho, D., & Chen, H. (2018). Deep Autoencoding Gaussian Mixture Model for Unsupervised Anomaly Detection. In International Conference on Learning Representations (ICLR 2018).
Open publication reference