code: def evaluation_metrics(y_valid, y_pred) -> Dict[str, float]:
      """
      Calculates model performance metrics (accuracy, precision, recall, etc)
      from the actual and predicted lables provided.
  
      Example
      ---------
  
      .. code-block:: python
  
          y_actual: np.ndarray
          y_predicted: np.ndarray
  
          metrics = xai.evaluation_metrics(y_actual, y_predicted)
          for k,v in metrics.items():
              print(f"{k}: {v}")
  
          > precision: 0.8,
          > recall: 0.9,
          > specificity: 0.7,
          > accuracy: 0.8,
          > auc: 0.7,
          > f1: 0.8
  
      Args
      -------
  
      y_valid :
          Numpy array with the actual labels for the datapoints
      y_pred :
          Numpy array with the predicted labels for the datapoints
  
      Returns
      ----------
  
      : Dict[str, float]
          Dictionary containing the metrics as follows:
  
          .. code-block:: python
  
              return {
                  "precision": precision,
                  "recall": recall,
                  "specificity": specificity,
                  "accuracy": accuracy,
                  "auc": auc,
                  "f1": f1
              }
  
      """
  
      TP = np.sum(y_pred[y_valid == 1])
      TN = np.sum(y_pred[y_valid == 0] == 0)
      FP = np.sum(y_pred[y_valid == 0])
      FN = np.sum(y_pred[y_valid == 1] == 0)
  
      # Adding an OR to ensure it doesn't divide by zero
      precision = TP / ((TP + FP) or 0.001)
      recall = TP / ((TP + FN) or 0.001)
      specificity = TN / ((TN + FP) or 0.001)
      accuracy = (TP + TN) / (TP + TN + FP + FN)
      f1 = 2 * (precision * recall) / ((precision + recall) or 0.001)
      try:
          auc = roc_auc_score(y_valid, y_pred)
      except ValueError:
          auc = 0
  
      return {
          "precision": precision,
          "recall": recall,
          "specificity": specificity,
          "accuracy": accuracy,
          "auc": auc,
          "f1": f1,
      }
  
imports: import pandas
  import matplotlib.pyplot
  import numpy
  from scipy.stats import spearmanr
  from scipy.cluster import hierarchy
  from typing import List, Any, Union, Tuple, Optional, Dict
  import random, math
  from sklearn.metrics import roc_curve, precision_recall_curve, roc_auc_score, confusion_matrix
  import itertools
  import logging
label_desc: Use image node_id 12 for calling a global function with example usage: evaluation_metrics(y_valid, y_pred) and returns: dict