fusilli.utils.metrics_utils

Calculates metrics of the models and houses list of the available metrics to use.

Classes

MetricsCalculator(base_model_instance)

Calculates metrics of the models and houses list of the available metrics to use.

class MetricsCalculator(base_model_instance)[source]

Bases: object

Calculates metrics of the models and houses list of the available metrics to use.

__init__(base_model_instance)[source]
Parameters:

base_model_instance (fusilli.fusionmodels.base_model.BaseModel) – Instance of the base model. Has information on the prediction task and multiclass dimensions if applicable.

accuracy(preds, labels, logits)[source]

Calculates accuracy.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

Accuracy value.

Return type:

float

auprc(preds, labels, logits)[source]

Calculates area under the precision-recall curve.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

AUPRC value.

Return type:

float

auroc(preds, labels, logits)[source]

Area under the receiver operating characteristic curve.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

AUROC value.

Return type:

float

balanced_accuracy(preds, labels, logits)[source]

Calculates balanced accuracy.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

Balanced accuracy value.

Return type:

float

f1(preds, labels, logits)[source]

Calculates F1 score. This is equivalent to the Dice coefficient.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

F1 score value.

Return type:

float

mae(preds, labels, logits)[source]

Calculates mean absolute error.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

MAE value.

Return type:

float

mse(preds, labels, logits)[source]

Calculates mean squared error.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

MSE value.

Return type:

float

precision(preds, labels, logits)[source]

Calculates precision.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

Precision value.

Return type:

float

r2(preds, labels, logits)[source]

Calculates R2 score.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

R2 score value.

Return type:

float

recall(preds, labels, logits)[source]

Calculates recall. This is equivalent to sensitivity.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

Recall value.

Return type:

float

specificity(preds, labels, logits)[source]

Calculates specificity.

Parameters:
  • preds (torch.Tensor) – Predicted values from the model.

  • labels (torch.Tensor) – True labels.

  • logits (torch.Tensor) – Probability values from the model.

Returns:

Specificity value.

Return type:

float