Shortcuts

torchtraining.metrics.classification.binary

class torchtraining.metrics.classification.binary.Accuracy(threshold: float = 0.0, reduction=<built-in method mean of type object>)[source]

Calculate accuracy score between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters
  • threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

  • reduction (Callable(torch.Tensor) -> Any, optional) – One argument callable getting torch.Tensor and returning argument after specified reduction. Default: torch.mean (mean across batch, user can use torchtraining.savers.Mean to get mean across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

If reduction is left as default mean is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.BalancedAccuracy(threshold: float = 0.0)[source]

Critical success index between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.ConfusionMatrix(threshold: float = 0.0, reduction=<built-in method sum of type object>)[source]

Confusion matrix between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters
  • threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

  • reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

If reduction is left as default sum is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.CriticalSuccessIndex(threshold: float = 0.0)[source]

Critical success index between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.F1(threshold: float = 0.0)[source]

F1 score between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.FBeta(beta: float, threshold: float = 0.0)[source]

Get f-beta score between outputs and targets.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters
  • beta (float) – Beta coefficient of f-beta score.

  • threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

  • data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

forward(data)[source]
class torchtraining.metrics.classification.binary.FalseDiscoveryRate(threshold: float = 0.0)[source]

False discovery rate between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.FalseNegative(threshold: float = 0.0, reduction=<built-in method sum of type object>)[source]

Number of false negatives between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters
  • threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

  • reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

If reduction is left as default sum is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.FalseNegativeRate(threshold: float = 0.0)[source]

False negative rate between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.FalseOmissionRate(threshold: float = 0.0)[source]

False omission rate between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.FalsePositive(threshold: float = 0.0, reduction=<built-in method sum of type object>)[source]

Number of false positives between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters
  • threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

  • reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

If reduction is left as default sum is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.FalsePositiveRate(threshold: float = 0.0)[source]

False positive rate between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.Jaccard(threshold: float = 0.0, reduction=<built-in method mean of type object>)[source]

Calculate jaccard score between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters
  • threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

  • reduction (Callable(torch.Tensor) -> Any, optional) – One argument callable getting torch.Tensor and returning argument after specified reduction. Default: torch.mean (mean across batch, user can use torchtraining.savers.Mean to get mean across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

If reduction is left as default mean is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.MatthewsCorrelationCoefficient(threshold: float = 0.0)[source]

Matthews correlation coefficient between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.NegativePredictiveValue(threshold: float = 0.0)[source]

Negative predictive value between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.Precision(threshold: float = 0.0)[source]

Precision between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.Recall(threshold: float = 0.0)[source]

Recall between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.Specificity(threshold: float = 0.0)[source]

Specificity between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters

threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.TrueNegative(threshold: float = 0.0, reduction=<built-in method sum of type object>)[source]

Number of true negatives between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters
  • threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

  • reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

If reduction is left as default sum is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.binary.TruePositive(threshold: float = 0.0, reduction=<built-in method sum of type object>)[source]

Number of true positives between output and target.

Works for both logits and probabilities of output.

If output is tensor after sigmoid activation user should change threshold to 0.5 for correct results (default 0.0 corresponds to unnormalized probability a.k.a logits).

Parameters
  • threshold (float, optional) – Threshold above which prediction is considered to be positive. Default: 0.0

  • reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,)(N, *) and contain logits or probabilities. targets should be of shape (N,)(N, *) as well and contain boolean values (or integers from set 0,1{0, 1} ).

Returns

If reduction is left as default sum is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor