Skip to content

spearman_correlation

allennlp.training.metrics.spearman_correlation

[SOURCE]


SpearmanCorrelation#

@Metric.register("spearman_correlation")
class SpearmanCorrelation(Metric):
 | def __init__(self) -> None

This Metric calculates the sample Spearman correlation coefficient (r) between two tensors. Each element in the two tensors is assumed to be a different observation of the variable (i.e., the input tensors are implicitly flattened into vectors and the correlation is calculated between the vectors).

https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient

__call__#

class SpearmanCorrelation(Metric):
 | ...
 | def __call__(
 |     self,
 |     predictions: torch.Tensor,
 |     gold_labels: torch.Tensor,
 |     mask: Optional[torch.BoolTensor] = None
 | )

Parameters

  • predictions : torch.Tensor
    A tensor of predictions of shape (batch_size, ...).
  • gold_labels : torch.Tensor
    A tensor of the same shape as predictions.
  • mask : torch.BoolTensor, optional (default = None)
    A tensor of the same shape as predictions.

get_metric#

class SpearmanCorrelation(Metric):
 | ...
 | @overrides
 | def get_metric(self, reset: bool = False)

Returns

  • The accumulated sample Spearman correlation.

reset#

class SpearmanCorrelation(Metric):
 | ...
 | @overrides
 | def reset(self)