physioex.train.metrics#

Functions

accuracy_score(outputs, targets[, ...])

Compute accuracy score.

cohen_kappa_score(outputs, targets[, ...])

confusion_matrix(outputs, targets[, ...])

f1_score(outputs, targets[, ignore_index, ...])

Compute F1 score.

kappa_from_confusion(cm)

Cohen's kappa of a confusion matrix; NaN when it is undefined.

mae_score(outputs, targets[, ignore_index])

Mean absolute error for regression tasks.

median_record_kappa(y_true_records, ...[, ...])

Median of the per-recording kappas, ignoring undefined (NaN) ones.

mse_score(outputs, targets[, ignore_index])

Mean squared error for regression tasks.

per_record_kappa(y_true_records, ...[, ...])

One kappa per recording (NaN where kappa is undefined).

pooled_kappa(y_true_records, y_pred_records, ...)

Kappa of the confusion matrix summed over all recordings (kappa_T).

precision_score(outputs, targets[, ...])

Compute precision score.

r2_score(outputs, targets[, ignore_index])

Coefficient of determination (R^2) for regression tasks.

recall_score(outputs, targets[, ...])

Compute recall score.

record_confusion_matrix(y_true, y_pred, ...)

Confusion matrix (rows = true, columns = predicted) of one recording.

support_score(outputs, targets[, ignore_index])

physioex.train.metrics.accuracy_score(outputs, targets, ignore_index=-1, average='micro')[source]#

Compute accuracy score.

Parameters:
  • outputs (Tensor) – Model outputs (logits), shape (…, n_classes).

  • targets (Tensor) – Ground-truth labels.

  • ignore_index (int) – Label value to ignore (default -1).

  • average (str) – Averaging method. "micro" computes global accuracy (correct / total). "weighted" is equivalent to "micro" for accuracy and is accepted for API consistency with the other metric functions.

Returns:

Accuracy as a float in [0, 1].

Return type:

float

physioex.train.metrics.f1_score(outputs, targets, ignore_index=-1, average='macro')[source]#

Compute F1 score.

Parameters:
  • outputs (Tensor) – Model outputs (logits), shape (…, n_classes).

  • targets (Tensor) – Ground-truth labels.

  • ignore_index (int) – Label value to ignore (default -1).

  • average (str) – "macro" returns unweighted mean of per-class F1 across classes with non-zero support. "weighted" weights each class F1 by its support (number of true instances).

Returns:

F1 score as a float in [0, 1].

Return type:

float

physioex.train.metrics.kappa_from_confusion(cm)[source]#

Cohen’s kappa of a confusion matrix; NaN when it is undefined.

Undefined cases: an empty matrix, or chance agreement equal to 1 (one class only in both rater marginals).

Return type:

float

physioex.train.metrics.mae_score(outputs, targets, ignore_index=-1)[source]#

Mean absolute error for regression tasks.

Parameters:
Return type:

float

physioex.train.metrics.median_record_kappa(y_true_records, y_pred_records, n_classes, ignore_index=-1)[source]#

Median of the per-recording kappas, ignoring undefined (NaN) ones.

Parameters:
  • n_classes (int)

  • ignore_index (int | None)

Return type:

float

physioex.train.metrics.mse_score(outputs, targets, ignore_index=-1)[source]#

Mean squared error for regression tasks.

Parameters:
Return type:

float

physioex.train.metrics.per_record_kappa(y_true_records, y_pred_records, n_classes, ignore_index=-1)[source]#

One kappa per recording (NaN where kappa is undefined).

Parameters:
  • n_classes (int)

  • ignore_index (int | None)

Return type:

np.ndarray

physioex.train.metrics.pooled_kappa(y_true_records, y_pred_records, n_classes, ignore_index=-1)[source]#

Kappa of the confusion matrix summed over all recordings (kappa_T).

Parameters:
  • n_classes (int)

  • ignore_index (int | None)

Return type:

float

physioex.train.metrics.precision_score(outputs, targets, ignore_index=-1, average='macro')[source]#

Compute precision score.

Parameters:
  • outputs (Tensor) – Model outputs (logits), shape (…, n_classes).

  • targets (Tensor) – Ground-truth labels.

  • ignore_index (int) – Label value to ignore (default -1).

  • average (str) – "macro" returns unweighted mean of per-class precision across classes with non-zero support. "weighted" weights each class precision by its support.

Returns:

Precision as a float in [0, 1].

Return type:

float

physioex.train.metrics.r2_score(outputs, targets, ignore_index=-1)[source]#

Coefficient of determination (R^2) for regression tasks.

Parameters:
Return type:

float

physioex.train.metrics.recall_score(outputs, targets, ignore_index=-1, average='macro')[source]#

Compute recall score.

Parameters:
  • outputs (Tensor) – Model outputs (logits), shape (…, n_classes).

  • targets (Tensor) – Ground-truth labels.

  • ignore_index (int) – Label value to ignore (default -1).

  • average (str) – "macro" returns unweighted mean of per-class recall across classes with non-zero support. "weighted" weights each class recall by its support.

Returns:

Recall as a float in [0, 1].

Return type:

float

physioex.train.metrics.record_confusion_matrix(y_true, y_pred, n_classes, ignore_index=-1)[source]#

Confusion matrix (rows = true, columns = predicted) of one recording.

y_true and y_pred are class indices of equal length (numpy arrays, lists or tensors). Epochs whose true label equals ignore_index (unscored or padding) are dropped.

Parameters:
  • n_classes (int)

  • ignore_index (int | None)

Return type:

np.ndarray