Pearson Corr. Coef.¶
Module Interface¶
- class torchmetrics.PearsonCorrCoef(compute_on_step=None, **kwargs)[source]
Computes Pearson Correlation Coefficient:
Where is a tensor of target values, and is a tensor of predictions.
Forward accepts
preds
(float tensor):(N,)
target``(float tensor): ``(N,)
- Parameters
Example
>>> 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)
Initializes internal Module state, shared by both nn.Module and ScriptModule.
Functional Interface¶
- torchmetrics.functional.pearson_corrcoef(preds, target)[source]
Computes pearson correlation coefficient.
Example
>>> from torchmetrics.functional import pearson_corrcoef >>> target = torch.tensor([3, -0.5, 2, 7]) >>> preds = torch.tensor([2.5, 0.0, 2, 8]) >>> pearson_corrcoef(preds, target) tensor(0.9849)
- Return type