Skip to content

Metrics compute nrmse

Compute the Normalized Root Mean Squared Error. This can be used to better compare models trained on different datasets with differnet scales, although it is not perfectly scale invariant.

Parameters:

Name Type Description Default
y_pred torch.Tensor

The predicted y values

required
y_true torch.Tensor

The true y values

required

Returns:

Type Description
torch.Tensor

The normalized root mean squared error

Source code in yeastdnnexplorer/ml_models/metrics.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def compute_nrmse(self, y_pred, y_true):
    """
    Compute the Normalized Root Mean Squared Error. This can be used to better compare
    models trained on different datasets with differnet scales, although it is not
    perfectly scale invariant.

    :param y_pred: The predicted y values
    :type y_pred: torch.Tensor
    :param y_true: The true y values
    :type y_true: torch.Tensor
    :return: The normalized root mean squared error
    :rtype: torch.Tensor

    """
    rmse = torch.sqrt(F.mse_loss(y_pred, y_true))

    # normalize with the range of true y values
    y_range = y_true.max() - y_true.min()
    nrmse = rmse / y_range
    return nrmse