npu.eval.classification_evaluation_utils

Classes

ClassificationEvaluationUtils()

class npu.eval.classification_evaluation_utils.ClassificationEvaluationUtils
Author:

Alberto M. Esmoris Pena

Util functions to handle the evaluation of classification tasks.

static g_oa(y, yhat)

Compute the overall accuracy (OA).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The overall accuracy (OA).

Return type:

float

static g_macc(y, yhat)

Compute the mean accuracy (mAcc).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The mean accuracy (mAcc).

Return type:

float

static g_p(y, yhat)

Compute the precision (P).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The precision (P).

Return type:

float

static g_r(y, yhat)

Compute the recall (R).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The recall (R).

Return type:

float

static g_f1(y, yhat)

Compute the F1 score (F1).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The F1 score (F1).

Return type:

float

static g_iou(y, yhat)

Compute the intersection over union (IoU).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The intersection over union (IoU).

Return type:

float

static g_wp(y, yhat)

Compute weighted precision (wP).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The weighted precision (wP).

Return type:

float

static g_wr(y, yhat)

Compute the weighted recall (wR).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The weighted recall (wR).

Return type:

float

static g_wf1(y, yhat)

Compute the weighted F1 score (F1).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The weighted F1 score (wF1)

Return type:

float

static g_wiou(y, yhat)

Compute the weighted intersection over union (wIoU).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The weighted intersection over union (wIoU).

Return type:

float

static g_mcc(y, yhat)

Compute the Matthew’s Correlation Coefficient (MCC).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The Matthew’s Correlation Coefficient (MCC).

Return type:

float

static g_kappa(y, yhat)

Compute the Cohen’s Kappa Score (Kappa).

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

Returns:

The Cohen’s Kappa Score (Kappa).

Return type:

float

static cw_acc(y, yhat, c)

Compute the accuracy for a given class.

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

  • c – The index of the class whose accuracy must be computed.

Returns:

The accuracy for the given class.

Return type:

float

static cw_p(y, yhat, c)

Compute the precision for a given class.

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

  • c – The index of the class whose precision must be computed.

Returns:

The precision for the given class.

Return type:

float

static cw_r(y, yhat, c)

Compute the recall for a given class.

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

  • c – The index of the class whose recall must be computed.

Returns:

The recall for the given class.

Return type:

float

static cw_f1(y, yhat, c)

Compute the F1 score for a given class.

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

  • c – The index of the class whose F1 score must be computed.

Returns:

The F1 score for the given class.

Return type:

float

static cw_iou(y, yhat, c)

Compute the Intersection over Union (IoU) score for a given class.

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

  • c – The index of the class whose Intersection over Union score must be computed.

Returns:

The Intersection over Union for the given class.

Return type:

float

static cw_mcc(y, yhat, c)

Compute the Matthew’s Correlation Coefficient (MCC) for a given class.

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

  • c – The index of the class whose F1 score must be computed.

Returns:

The Matthew’s Correlation Coefficient (MCC).

Return type:

float

static cw_kappa(y, yhat, c)

Compute the Cohen’s Kappa score for a given class.

Parameters:
  • y – Reference/expected classes.

  • yhat – Predicted classes.

  • c – The index of the class whose Cohen’s Kappa score must be computed.

Returns:

The Cohen’s Kappa score for the given class.

Return type:

float

static generate_global_eval_string(metric_names, metric_scores)

Generate the string representing the global evaluation from given metrics.

Parameters:
  • metric_names (list of str) – The names of the given metrics.

  • metric_scores (list of float or np.ndarray of float) – The values for the given metrics.

Returns:

The string representing the global evaluation.

Return type:

str

static generate_classwise_eval_string(class_names, class_metric_names, class_metric_scores)

Generate the string representing the class-wise evaluation from given metrics.

Parameters:
  • class_names (list of str) – The names of the given classes.

  • class_metric_names (list of str) – The names of the given class-wise metrics.

  • class_metric_scores (list of float or np.ndarray of float) – The values for the given class-wise metrics.

Returns:

The string representing the class-wise evaluation.

Return type:

str

static generate_confusion_matrix_string(conf_mat, names=None)

Generate the string representing the given confusion matrix.

Parameters:
  • conf_mat (str) – The confusion matrix to be represented as a string.

  • names (None or list of str) – The name for each class.

Returns:

The string representing the confusion matrix.

Return type:

str