ThresholdAccuracy#
- class torch_uncertainty.metrics.regression.ThresholdAccuracy(power, lmbda=1.25, **kwargs)[source]#
Computes the Threshold Accuracy metric, also referred to as d1, d2, or d3.
This metric evaluates the percentage of predictions that fall within a specified threshold of their corresponding target values. The threshold is determined based on the maximum ratio between predictions and targets (or its inverse), raised to a specified power.
- Parameters:
power – The power to raise the threshold to. Often in [1, 2, 3].
lmbda – The threshold to compare the max of ratio of predictions to targets and its inverse to. Defaults to
1.25.
kwargs – Additional keyword arguments, see Advanced metric settings.
Example:
from torch_uncertainty.metrics.regression import ThresholdAccuracy import torch # Initialize the metric with power=2 and lambda=1.25 threshold_accuracy = ThresholdAccuracy(power=2, lmbda=1.25) # Example predictions and targets preds = torch.tensor([2.0, 3.0, 5.0, 8.0, 20.0]) target = torch.tensor([2.1, 2.5, 4.5, 10.0, 10.0]) # Update the metric state threshold_accuracy.update(preds, target) # Compute the Threshold Accuracy result = threshold_accuracy.compute() print(f"Threshold Accuracy: {result.item():.2f}") # Output: Threshold Accuracy: 0.80