NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Dealing with Uncertainty in Contextual Anomaly Detection

Luca Bindini, Lorenzo Perini, Stefano Nistri, Jesse Davis, Paolo Frasconi

TL;DR

Contextual anomaly detection often struggles to separate natural data variance from a genuine lack of training data. This paper introduces the Normalcy Score (NS), a framework based on heteroscedastic Gaussian processes that treats the classic Z-score as a random variable. By explicitly modeling both aleatoric and epistemic uncertainties, NS provides highly accurate anomaly detection alongside robust confidence intervals, enabling safer, uncertainty-aware decision-making in high-stakes fields like healthcare.

What Problem Does This Paper Address?

Contextual Anomaly Detection (CAD) identifies anomalies in a target variable ($y$) based on a set of contextual variables ($x$). For example, determining if a patient's aorta diameter is abnormally large requires conditioning on their age, sex, weight, and height.

A major limitation of existing CAD methods is their inability to answer a critical question: Is an anomaly score high because of intrinsic patient variability (aleatoric uncertainty), or because the model has never seen a patient with this specific combination of traits before (epistemic uncertainty)? Conflating these two uncertainties can lead to dangerous false positives or overconfident, incorrect diagnoses in underrepresented demographics. Furthermore, traditional statistical approaches like the classic Z-score assume uniform variance across all contexts (homoscedasticity), which fails when data variability inherently shifts depending on the context.

Methods

The authors propose the Normalcy Score (NS) framework, which reformulates the traditional Z-score as a random variable using Heteroscedastic Gaussian Process Regression (HGPR).

  • Dual Gaussian Processes: Instead of assuming uniform variance, NS uses two independent GPs: $f_1(x)$ to model the context-dependent mean, and $f_2(x)$ to model the log-standard deviation (ensuring the predicted standard deviation remains strictly positive).
  • Uncertainty Disentanglement: Aleatoric uncertainty (AU) is captured directly by the second GP ($f_2$), while epistemic uncertainty (EU) is derived from the posterior variances of both $f_1$ and $f_2$.
  • Highest-Density Interval (HDI): Because the Z-score is treated as a random variable, the framework can compute a 95% HDI via posterior sampling and numerical integration. A wide interval signals high epistemic uncertainty, allowing the system to "abstain" from making a risky prediction when data is sparse.
  • Scalability: Standard GPs scale poorly ($O(N^3)$). To make the framework practical for larger datasets, the authors implement a sparse approximation using inducing variables, bringing the runtime complexity down to $O(M^2N)$.

Datasets

The framework was evaluated on both synthetic and real-world data:

  • UCI Benchmark Datasets: Five standard datasets (Abalone, Concrete, SynMachine, Toxicity, Yacht) were modified by injecting synthetic contextual anomalies to evaluate detection accuracy under controlled conditions (summarized in figure:art_225c342c727541dab7e63b2b8ae733a9).
  • Real-World Medical Dataset: A clinical cohort consisting of 1,110 normal subjects and 351 patients with bicuspid aortic valve (a condition linked to dangerous aortic dilations). The target variables were aorta diameters measured at two locations: the sinus of Valsalva (SoV) and the ascending aorta (AA), conditioned on age, gender, weight, and height.
Table 1: Summary of UCI benchmark datasets with injected anomalies.

Key Insights and Ideas

  • The Power of Abstention: By tracking the 95% HDI, the model can flag when it is operating in a "data desert." In clinical practice, a doctor can be warned that the model's anomaly score is unreliable due to a lack of similar historical patient data, prompting manual review or further testing.
  • Context-Driven Variance: What is normal for one context might be highly anomalous for another. Modeling variance as a function of context prevents the overestimation of anomalies in low-variance regions and underestimation in high-variance regions.
  • Z-score Baselines are Underrated: The authors demonstrate that a simple, properly tuned Z-score baseline actually outperforms several complex non-contextual machine learning methods (like standard Isolation Forests), serving as a vital benchmark that prior CAD literature frequently overlooked.
Comparison of anomaly detection methods on simulated WHO growth curves.

Key Results

  • Benchmark Performance: NS consistently achieved the top ROC AUC and PR AUC across almost all UCI datasets, outperforming state-of-the-art CAD methods like QCAD and ROCOD. For instance, it achieved a perfect 1.00 AUC on the SynMachine dataset and a strong 0.97 ROC AUC / 0.88 PR AUC on the Yacht dataset.
  • Clinical Success: On the real-world medical dataset, NS achieved superior performance in detecting aortic dilations compared to its contextual competitors, with statistically significant improvements verified by the Delong test ($p < 0.001$).
  • Uncertainty Alignment: The length of the 95% HDI showed a strong positive correlation (quantified via Weighted Kendall Tau) with data sparsity, proving that the interval genuinely reflects epistemic uncertainty.

Limitations and Future Work

  • Scalar Restrictions: The current framework only handles a single scalar behavioral variable ($y$). It cannot jointly model vector-valued behaviors, such as the full multi-dimensional shape or geometry of an organ.
  • Future Directions: The authors plan to extend NS to multi-output or multi-task Gaussian processes, as well as incorporate Wishart process priors to explicitly capture correlations between multiple interconnected behavioral variables.

Summary updated

BibTeX
@article{bindini2026dealing,
  author = {Luca Bindini and Lorenzo Perini and Stefano Nistri and Jesse Davis and Paolo Frasconi},
  title = {{Dealing with Uncertainty in Contextual Anomaly Detection}},
  journal = {Trans. Mach. Learn. Res.},
  year = {2026},
}
Figure