code: def get_metrics_multiclass(
      y_true,
      y_pred,
      y_pred_probs,
      include_per_class=False,
      include_curves=False,
  ):
      results = {
          Metrics.ACCURACY: accuracy_score(y_true, y_pred),
          Metrics.COHEN_KAPPA: cohen_kappa_score(y_true, y_pred),
          Metrics.F1_MICRO: f1_score(y_true, y_pred, average="micro"),
          Metrics.F1_MACRO: f1_score(y_true, y_pred, average="macro"),
          Metrics.ROC_AUC_MICRO: np.nan,
          Metrics.ROC_AUC_MACRO: np.nan,
          Metrics.RANK_ACCURACY: np.nan,
      }
  
      # this parameter is most relevant for datasets with high-cardinality
      # labels (lots of poosible values)
      # TODO: make the rank parameter configurable
      results[Metrics.RANK_ACCURACY] = rank_n_accuracy(
          y_true=y_true, y_prob_mat=y_pred_probs
      )
  
      # if possible, compute multi-label AUC metrics
      present_classes = np.unique(y_true)
      all_labels_same = len(present_classes) == 1
      any_probs_nan = np.any(np.isnan(y_pred_probs))
      if not (all_labels_same or any_probs_nan):
          # get binary label matrix, ignoring classes that aren't present
          y_true_bin = get_per_class_matrix(y_true)
  
          # filter out probabilities for classes that aren't in this sample
          filtered_probs = y_pred_probs[:, present_classes]
  
          # actually compute roc_auc score
          results[Metrics.ROC_AUC_MICRO] = roc_auc_score(
              y_true_bin, filtered_probs, average="micro"
          )
          results[Metrics.ROC_AUC_MACRO] = roc_auc_score(
              y_true_bin, filtered_probs, average="macro"
          )
  
      # TODO: multi-label AP metrics?
  
      # labelwise controls whether to compute separate metrics for each posisble label
      if include_per_class or include_curves:
          results["class_wise"] = {}
  
          # create binary matrices, including classes that aren't actually present
          all_classes = list(range(y_pred_probs.shape[1]))
          y_true_bin = get_per_class_matrix(y_true, classes=all_classes)
          y_pred_bin = get_per_class_matrix(y_pred, classes=all_classes)
  
          # for each possible class, generate F1, precision-recall, and ROC scores
          # using the binary metrics function.
          for cls in all_classes:
              class_pred_probs = np.column_stack(
                  (1 - y_pred_probs[:, cls], y_pred_probs[:, cls])
              )
              class_res = get_metrics_binary(
                  y_true=y_true_bin[:, cls],
                  y_pred=y_pred_bin[:, cls],
                  y_pred_probs=class_pred_probs,
                  include_curves=include_curves,
              )
              results["class_wise"][cls] = class_res
  
      return results
  
file_path: ATM/atm/metrics.py
imports: from __future__ import absolute_import, division, unicode_literals
  from builtins import range
  import numpy
  import pandas
  from sklearn.metrics import accuracy_score, average_precision_score, cohen_kappa_score, f1_score, matthews_corrcoef, precision_recall_curve, roc_auc_score, roc_curve
  from sklearn.model_selection import StratifiedKFold
  from atm.constants import METRICS_BINARY, METRICS_MULTICLASS, N_FOLDS_DEFAULT, Metrics
label_desc: Use image node_id 5 for calling a global function with example usage: get_metrics_multiclass(y_true, y_pred, y_pred_probs, include_per_class, include_curves) and returns: results