To Trust Or Not To Trust A Classifier

Heinrich Jiang, Been Kim, Maya R. Gupta

Introduction

Machine learning models are notoriously overconfident, often "hallucinating" certainty even when they are incorrect. In high-stakes applications like medical diagnosis or autonomous driving, knowing when a model is likely to fail is as critical as its overall accuracy. Most practitioners rely on a model’s internal confidence—such as the "softmax" probability in a neural network. However, these internal scores are frequently poorly calibrated; a model might assign a 99% probability to a prediction simply because the input is far from the decision boundary, even if that input looks nothing like the training data.

This paper introduces the Trust Score, a model-agnostic metric that uses the density of training data to determine if a classifier’s prediction should be believed. By measuring how far a test point is from its predicted class versus the nearest alternative class, the Trust Score consistently outperforms standard confidence scores in identifying misclassifications.

Methodology

The authors propose a two-step algorithm to calculate the Trust Score:

  1. Density Filtering: For each class in the training set, the algorithm identifies and removes outliers or low-density points. It does this by looking at the $k$-nearest neighbors of each point; if a point is in a sparse region, it is filtered out. This leaves behind an "$\alpha$-high-density-set" for each class, representing the core, reliable regions of the data distribution.
  2. The Distance Ratio: When a new test point arrives, the model makes a prediction. The Trust Score is then calculated as the ratio of two distances:
  3. The distance from the test point to the nearest different class (the closest class that the model didn't pick).
  4. The distance from the test point to the class the model did pick.

$$\text{Trust Score} = \frac{\text{Distance to nearest other class}}{\text{Distance to predicted class}}$$

A high score means the point is deep within the territory of the predicted class and far from any rivals. A low score (near or below 1) suggests the point is actually closer to a different class than the one the model chose, signaling a likely mistake.

Experimental Evaluation

The authors evaluated their method across a diverse range of benchmarks, including six classic UCI datasets (Phonemes, Seeds, Parkinsons, Letters, Wilt, and Iris) and high-dimensional image benchmarks such as MNIST, SVHN, and CIFAR-10/100. For the image datasets, trust scores were calculated based on the activations of intermediate layers in deep neural networks, rather than raw pixels, to better capture the model's learned feature space.

Results and Discussion

The Trust Score consistently achieved higher precision in identifying correctly and incorrectly classified examples compared to the model’s own confidence or a standard 1-nearest-neighbor baseline.

Precision of Trust Score vs. Model Confidence and 1-NN Ratio across various UCI datasets and models.

Key Findings

  • Superior Precision: On the UCI datasets, the Trust Score (solid purple line) consistently maintains higher precision across percentile levels compared to internal model confidence (dashed red line).
  • Identifying "Suspicious" Examples: When focusing on the bottom percentiles of Trust Scores (the "most suspicious" predictions), the misclassification rate was significantly higher than if they had used the model's softmax scores to find errors.
Comprehensive results showing precision for standard classification (top) and the specific task of detecting suspicious examples (bottom).
  • Deep Learning Synergy: In neural networks, the Trust Score worked best when applied to intermediate layers. This suggests that the "trustworthiness" of a point is best evaluated in the feature space the model has learned to prioritize.
  • Model Agnostic: The score worked effectively across different architectures, including Neural Networks and Random Forests, demonstrating its versatility.

Conclusion

The Trust Score provides a principled way to audit classifier reliability by grounding predictions in the density of the training data. While calculating nearest-neighbor distances for massive datasets remains a computational bottleneck, the method's ability to provide a reliable "second opinion" makes it a valuable tool for high-stakes machine learning applications. Future work will likely focus on optimizing these calculations for real-time, large-scale deployment.

Summary updated

BibTeX
@inproceedings{jiang2018trust,
  author = {Heinrich Jiang and Been Kim and Maya R. Gupta},
  title = {{To Trust Or Not To Trust A Classifier}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2018},
  url = {https://openreview.net/forum?id=HkZFuPbubr},
}
Figure