- Introduced by
- Combination of autoencoder anomaly detection (Hinton & Salakhutdinov, 2006) and XAI methods (e.g., Lundberg & Lee, 2017)
- Year
- 2017-2019
- Type
- Unsupervised anomaly detection with post-hoc or intrinsic explainability
- Family
- Machine learning
What does it do?
Explainable Autoencoder Anomaly Detection pairs an autoencoder-based anomaly detector with an explanation step that attributes each flagged observation's score to its input features.
The explanation can come from per-feature reconstruction error or from SHAP or LIME applied to the score. The detector's reconstruction-error score is unchanged; the added layer shows how each flagged score is distributed across features, for example which features the autoencoder reconstructed poorly.
The intuition behind the method
An autoencoder learns to compress and reconstruct normal data, so unusual observations tend to be reconstructed poorly and produce high reconstruction error. A plain reconstruction-error score, however, says nothing about why a sample is anomalous. Explainable variants add an interpreter on top of the detector, usually per-feature reconstruction error, SHAP, or LIME, so that for each flagged case the analyst can see which features contribute most to the score, such as those the model failed to reconstruct. This matters in domains such as fraud, network security, and medical monitoring, where an alert often needs a stated justification.
History
Autoencoders for deep dimensionality reduction are associated with Hinton and Salakhutdinov's 2006 work, which concerns representation learning rather than anomaly detection. Their use for anomaly detection was surveyed by Chalapathy and Chawla (2019). The explanation layer draws on general interpretability methods: SHAP (Lundberg and Lee, 2017) and LIME, a local surrogate approach, which were applied to anomaly detectors later on. The combined method therefore has no single originating publication.
When to use it
Choose this method when most of your data is unlabelled and the task is to detect departures from a learned pattern of normal behaviour, and when each alert must come with an explanation of which features contributed. It suits high-dimensional or multivariate numeric data, such as network traffic, industrial sensor arrays, or physiological signals, where feature-level attribution is useful for diagnosis. Do not use it when a substantial set of labelled anomalies is available, since a supervised classifier is then the better-posed problem and can provide its own feature attributions. It is also a poor fit when the bottleneck is too small to capture normal variation, which produces false positives, or when the compute needed to train a deep network is not available.
Limitations and considerations
- The reconstruction-error threshold strongly affects the trade-off between false positives and missed anomalies, and it is not set by the method itself.
- SHAP attributions for a neural network are estimates, and they can vary between retrained autoencoders with different initialisations.
- A deep autoencoder needs more data, compute, and tuning than shallow detectors such as Isolation Forest.
- The learned notion of normal depends entirely on the training data; contamination of that data degrades both detection and the explanations built on it.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Works without labelled anomaly examples, so it can be used when anomalies are rare or not defined in advance.
- Per-feature reconstruction error gives an explanation that is intrinsic to the autoencoder, with no separate surrogate model required.
- SHAP applied to the reconstruction-error function yields Shapley-value attributions per flagged observation, which are grounded in a defined additive attribution framework.
- Extends to high-dimensional inputs such as sensor arrays and time series, where simple distance-based detectors can struggle.
- The architecture is flexible: LSTM-autoencoders and convolutional autoencoders extend the approach to sequential and spatial data.
Applications
- Network intrusion detection, with feature-level attribution of flagged traffic.
- Credit card fraud detection, where each flagged transaction needs a stated reason.
- Predictive maintenance on industrial sensors, identifying which channels drive an alert.
- Medical time-series monitoring, where an alert must be justifiable to clinical staff.
- Manufacturing quality control, attributing defect signals to specific sensor channels.
How it works
How it works
An autoencoder neural network, with encoder layers, a bottleneck, and decoder layers, is trained on data assumed to be normal. Numeric features should first be standardised using means and standard deviations computed from the normal training data only, because the squared residual used as the score depends on feature scale. Without this step, features with large numeric ranges dominate both the score and the per-feature attributions. The network learns a compressed latent representation that is sufficient to reconstruct typical inputs. Because it is fitted to normal data, it is expected to reconstruct anomalies less accurately, though this is not guaranteed.
For each new observation, the trained autoencoder produces a reconstruction. The anomaly score is the squared Euclidean norm of the residual between the input and its reconstruction, as given in the formula for this step. Per-feature squared residuals can be inspected separately, and they sum to this score. Because each squared residual grows with the scale of its feature, a feature's contribution reflects its units as well as how poorly it was reconstructed.
Formula
e_i = \|x_i - \hat{x}_i\|^2A decision threshold on the reconstruction error is chosen. A common choice is a high percentile of scores on held-out normal data, such as the 95th or 99th. If labelled anomalies are available, the threshold can instead be tuned on a precision-recall criterion.
Samples whose reconstruction error exceeds the threshold are flagged as anomalies. At this stage the output is a binary label or a ranked score, the same as for a plain autoencoder detector.
An explanation step decomposes each flagged score. Per-feature reconstruction error shows which dimensions were poorly reconstructed. SHAP can be applied to the reconstruction-error function to give Shapley-value attributions for each feature. LIME instead fits a local linear surrogate, which gives an approximate attribution without the same axiomatic grounding.
Common pitfalls
- Fixing the threshold at an arbitrary value, such as 0.5, instead of calibrating it on the score distribution of normal data.
- Training and scoring on unscaled features, so that features with large numeric ranges dominate the squared residual and both the score and its per-feature attributions reflect units rather than deviation from normal behaviour.
- Reporting SHAP importances averaged over all flagged samples rather than per-instance attributions, which hides different anomaly types behind one ranking.
- Overlooking anomalies that the autoencoder reconstructs well because they resemble normal data, so they never exceed the threshold.
- Reading a larger reconstruction error as a more severe anomaly without first checking that the threshold and score scale are calibrated.
- Treating per-feature attributions as the causal explanation of an anomaly. They show how the score is distributed across features, and correlated features can share or mask part of the residual.
- Training on data that contains a meaningful share of anomalies, which shifts the learned baseline toward the anomalies.
Frequently asked questions
How is this different from a plain autoencoder anomaly detector?
A plain detector outputs only an anomaly score. The explainable variant adds a decomposition step, either per-feature reconstruction error or SHAP/LIME attributions, that shows how each flagged score is distributed across the input features. These attributions describe contribution to the score, such as features the autoencoder reconstructed poorly; they do not establish that those features caused the anomaly.
Which XAI method works best with autoencoders?
Per-feature reconstruction error is the simplest explanation and is intrinsic to the model, so it is a sensible default to report. It describes where reconstruction failed, not what caused the anomaly. SHAP gives Shapley-value attributions but adds computation cost. LIME gives a local linear surrogate that is cheaper but less formally grounded. The choice depends on how detailed the explanation must be and on the available compute.
How do I choose the anomaly threshold?
Fit the autoencoder on normal training data, compute the reconstruction-error distribution on a held-out normal validation set, and set the threshold at a high percentile, such as the 95th or 99th. If labelled anomalies are available, tune the threshold on the precision-recall trade-off that matters for your application.
Can this method be used on time-series data?
Yes. Replace the feedforward autoencoder with an LSTM-autoencoder or a temporal convolutional autoencoder to capture sequential dependencies. SHAP support for recurrent and convolutional networks depends on the implementation, so check that support before relying on SHAP attributions for a sequence model. Per-feature reconstruction error does not depend on that support.
What sample size is needed?
The method does not fix a required sample size. A deep autoencoder needs enough normal data to learn a stable reconstruction, and the requirement grows with input dimensionality and architecture size. With small normal datasets, a shallower autoencoder with a tight bottleneck is easier to fit, or a simpler detector such as Isolation Forest with SHAP explanations may be more appropriate.
Related methods
Sources
Lundberg, S. M., & Lee, S.-I. (2017). A unified approach to interpreting model predictions. Advances in Neural Information Processing Systems, 30.
Open publication referenceChalapathy, R., & Chawla, S. (2019). Deep learning for anomaly detection: A survey. arXiv preprint arXiv:1901.03407.
Open publication reference