code: def balanced_accuracy_score(
      y_true, y_pred, sample_weight=None, adjusted=False
  ):
      C = confusion_matrix(y_true, y_pred, sample_weight=sample_weight)
      with np.errstate(divide="ignore", invalid="ignore"):
          per_class = np.diag(C) / C.sum(axis=1)
      if np.any(np.isnan(per_class)):
          warnings.warn("y_pred contains classes not in y_true")
          per_class = per_class[~np.isnan(per_class)]
      score = np.mean(per_class)
      if adjusted:
          n_classes = len(per_class)
          chance = 1 / n_classes
          score -= chance
          score /= 1 - chance
      return score
  
imports: import numpy
  from sklearn import model_selection
  from sklearn.metrics import confusion_matrix, mean_squared_error
  from sklearn import metrics
  from sklearn import model_selection, metrics
  from sklearn.metrics import accuracy_score, f1_score, roc_auc_score, log_loss
  from sklearn.metrics import mean_squared_error, median_absolute_error, mean_absolute_error
  from sklearn.metrics import classification_report, confusion_matrix, mean_squared_log_error
  from sklearn.metrics import precision_recall_curve
  from sklearn.model_selection import cross_val_score, StratifiedKFold, KFold
  from sklearn.metrics import make_scorer
  from sklearn.metrics import accuracy_score
  from sklearn.metrics import average_precision_score
  from sklearn.metrics import f1_score
  from sklearn.metrics import log_loss
  from sklearn.metrics import precision_score
  from sklearn.metrics import recall_score
  from sklearn.metrics import roc_auc_score
  from sklearn.metrics import fbeta_score
  from sklearn.metrics import confusion_matrix
label_desc: Use image node_id 1 for calling a global function with example usage: balanced_accuracy_score(y_true, y_pred, sample_weight, adjusted) and returns: score