Regression Metrics
参考地址:Module metrics — PyTorch-Metrics 0.4.0 documentation (torchmetrics.readthedocs.io)
CosineSimilarity
计算target和preds之间的CosineSimilarity公式:
where is a tensor of target values, and
is a tensor of predictions.
Forward accepts
preds
(float tensor):(N,d)
target
(float tensor):(N,d)
>>> from torchmetrics import CosineSimilarity
>>> target = torch.tensor([[0, 1], [1, 1]])
>>> preds = torch.tensor([[0, 1], [0, 1]])
>>> cosine_similarity = CosineSimilarity(reduction = 'mean')
>>> cosine_similarity(preds, target)
tensor(0.8536)
ExplainedVariance
ExplainedVariance计算公式:
Where is a tensor of target values, and
is a tensor of predictions.
Forward accepts
preds
(float tensor):(N,)
or(N, ...)
(multioutput)target
(long tensor):(N,)
or(N, ...)
(multioutput)
在多输出的情况下,默认情况下,方差将在附加维度上均匀平均。 请参阅参数 multioutput 以更改此行为。
Example
>>>
>>> from torchmetrics import ExplainedVariance
>>> target = torch.tensor([3, -0.5, 2, 7])
>>> preds = torch.tensor([2.5, 0.0, 2, 8])
>>> explained_variance = ExplainedVariance()
>>> explained_variance(preds, target)
tensor(0.9572)
>>> target = torch.tensor([[0.5, 1], [-1, 1], [7, -6]])
>>> preds = torch.tensor([[0, 2], [-1, 2], [8, -5]])
>>> explained_variance = ExplainedVariance(multioutput='raw_values')
>>> explained_variance(preds, target)
tensor([0.9677, 1.0000])
MeanAbsoluteError
MeanAbsoluteError(MAE)计算公式:
Where is a tensor of target values, and
is a tensor of predictions.
>>> from torchmetrics import MeanAbsoluteError
>>> target = torch.tensor([3.0, -0.5, 2.0, 7.0])
>>> preds = torch.tensor([2.5, 0.0, 2.0, 8.0])
>>> mean_absolute_error = MeanAbsoluteError()
>>> mean_absolute_error(preds, target)
tensor(0.5000)
MeanAbsolutePercentageError
MeanAbsolutePercentageError(MAPE)计算公式:
>>> from torchmetrics import MeanAbsolutePercentageError
>>> target = torch.tensor([1, 10, 1e6])
>>> preds = torch.tensor([0.9, 15, 1.2e6])
>>> mean_abs_percentage_error = MeanAbsolutePercentageError()
>>> mean_abs_percentage_error(preds, target)
tensor(0.2667)
MeanSquaredError
MeanSquaredError(MSE)计算公式:
Where is a tensor of target values, and
is a tensor of predictions.
>>> from torchmetrics import MeanSquaredError
>>> target = torch.tensor([2.5, 5.0, 4.0, 8.0])
>>> preds = torch.tensor([3.0, 5.0, 2.5, 7.0])
>>> mean_squared_error = MeanSquaredError()
>>> mean_squared_error(preds, target)
tensor(0.8750)
MeanSquaredLogError
MeanSquaredLogError(MSLE):
Where is a tensor of target values, and
is a tensor of predictions.
>>> from torchmetrics import MeanSquaredLogError
>>> target = torch.tensor([2.5, 5, 4, 8])
>>> preds = torch.tensor([3, 5, 2.5, 7])
>>> mean_squared_log_error = MeanSquaredLogError()
>>> mean_squared_log_error(preds, target)
tensor(0.0397)
PearsonCorrcoef
PearsonCorrcoef计算公式:
Where is a tensor of target values, and
is a tensor of predictions.
Forward accepts
preds
(float tensor):(N,)
target``(float tensor): ``(N,)
>>> from torchmetrics import PearsonCorrcoef
>>> target = torch.tensor([3, -0.5, 2, 7])
>>> preds = torch.tensor([2.5, 0.0, 2, 8])
>>> pearson = PearsonCorrcoef()
>>> pearson(preds, target)
tensor(0.9849)
PSNR
自 v0.4 版后已弃用:PSNR 已移至 torchmetrics.image.psnr。 它将在 v0.5 中删除。
初始化内部模块状态,由 nn.Module 和 ScriptModule 共享。s
R2Score
R2Score,计算 r2 分数也称为决定系数:
应作为调整后的参数提供。
Forward accepts
preds
(float tensor):(N,)
or(N, M)
(multioutput)target
(float tensor):(N,)
or(N, M)
(multioutput)
在多输出的情况下,默认情况下,方差将在附加维度上均匀平均。 请参阅参数 multioutput 以更改此行为。
Example
>>>
>>> from torchmetrics import R2Score
>>> target = torch.tensor([3, -0.5, 2, 7])
>>> preds = torch.tensor([2.5, 0.0, 2, 8])
>>> r2score = R2Score()
>>> r2score(preds, target)
tensor(0.9486)
>>>
>>> target = torch.tensor([[0.5, 1], [-1, 1], [7, -6]])
>>> preds = torch.tensor([[0, 2], [-1, 2], [8, -5]])
>>> r2score = R2Score(num_outputs=2, multioutput='raw_values')
>>> r2score(preds, target)
tensor([0.9654, 0.9082])
SpearmanCorrcoef
计算 spearmans 等级相关系数。
其中 rg_x 和 rg_y 是与变量 x 和 y 关联的等级。 Spearmans 相关系数对应于对秩变量计算的标准 pearson 相关系数。
Example
>>>
>>> from torchmetrics import SpearmanCorrcoef
>>> target = torch.tensor([3, -0.5, 2, 7])
>>> preds = torch.tensor([2.5, 0.0, 2, 8])
>>> spearman = SpearmanCorrcoef()
>>> spearman(preds, target)
tensor(1.0000)
SSIM
自 v0.4 版后已弃用:SSIM 已移至 torchmetrics.image.ssim。 它将在 v0.5 中删除。
初始化内部模块状态,由 nn.Module 和 ScriptModule 共享。