MeanSquaredLogError#
- class torch_uncertainty.metrics.regression.MeanSquaredLogError(squared=True, **kwargs)[source]#
Computes the Mean Squared Logarithmic Error (MSLE) regression metric.
This metric is commonly used in regression problems where the relative difference between predictions and targets is of greater importance than the absolute difference. It is particularly effective for datasets with wide-ranging magnitudes, as it penalizes underestimation more than overestimation.
\[\text{MSELog} = \frac{1}{N}\sum_i^N (\log \hat{y_i} - \log y_i)^2\]where \(y\) is a tensor of target values, and \(\hat{y}\) is a tensor of predictions.
As input to
forward
andupdate
the metric accepts the following input:preds (
Tensor
): Predictions from modeltarget (
Tensor
): Ground truth values
As output of
forward
andcompute
the metric returns the following output:mse_log (
Tensor
): A tensor with the relative mean absolute error over the state
- Parameters:
squared – If True returns MSELog value, if False returns EMSELog value.
kwargs – Additional keyword arguments, see Advanced metric settings.
Example:
from torch_uncertainty.metrics.regression import MeanSquaredLogError import torch # Initialize the metric msle_metric = MeanSquaredLogError(squared=True) # Example predictions and targets (must be non-negative) preds = torch.tensor([2.5, 1.0, 2.0, 8.0]) target = torch.tensor([3.0, 1.5, 2.0, 7.0]) # Update the metric state msle_metric.update(preds, target) # Compute the Mean Squared Logarithmic Error result = msle_metric.compute() print(f"Mean Squared Logarithmic Error: {result.item()}") # Output: Mean Squared Logarithmic Error: 0.05386843904852867