torcheval.metrics.functional.weighted_calibration¶
-
torcheval.metrics.functional.
weighted_calibration
(input: Tensor, target: Tensor, weight: Union[float, int, Tensor] = 1.0, *, num_tasks: int = 1) Tensor [source]¶ Compute weighted calibration metric. When weight is not provided, it calculates the unweighted calibration. Its class version is
torcheval.metrics.WeightedCalibration
.weighted_calibration = sum(input * weight) / sum(target * weight)
Parameters: - input (Tensor) – Tensor of input values.
- target (Tensor) – Tensor of binary targets
- weight (optional) – Float or Int or Tensor of input weights. It is default to 1.0. If weight is a Tensor, its size should match the input tensor size.
- num_tasks (int) – Number of tasks that need weighted_calibration calculation. Default value is 1.
Returns: The return value of weighted calibration for each task (num_tasks,).
Return type: Tensor
Raises: ValueError – If value of weight is neither a
float
nor aint
nor atorch.Tensor
that matches the input tensor size.Examples:
>>> import torch >>> from torcheval.metrics.functional import weighted_calibration >>> weighted_calibration(torch.tensor([0.8, 0.4, 0.3, 0.8, 0.7, 0.6]),torch.tensor([1, 1, 0, 0, 1, 0])) tensor([1.2]) >>> weighted_calibration(torch.tensor([0.8, 0.4, 0.3, 0.8, 0.7, 0.6]),torch.tensor([1, 1, 0, 0, 1, 0]), torch.tensor([0.5, 1., 2., 0.4, 1.3, 0.9])) tensor([1.1321]) >>> weighted_calibration( torch.tensor([[0.8, 0.4], [0.8, 0.7]]), torch.tensor([[1, 1], [0, 1]]), num_tasks=2, ), >>> tensor([0.6000, 1.5000])