code: def balanced_accuracy_score(
      y_true, y_pred, *, sample_weight=None, adjusted=False
  ):
      """Compute the balanced accuracy.
  
      The balanced accuracy in binary and multiclass classification problems to
      deal with imbalanced datasets. It is defined as the average of recall
      obtained on each class.
  
      The best value is 1 and the worst value is 0 when ``adjusted=False``.
  
      Read more in the :ref:`User Guide <balanced_accuracy_score>`.
  
      .. versionadded:: 0.20
  
      Parameters
      ----------
      y_true : array-like of shape (n_samples,)
          Ground truth (correct) target values.
  
      y_pred : array-like of shape (n_samples,)
          Estimated targets as returned by a classifier.
  
      sample_weight : array-like of shape (n_samples,), default=None
          Sample weights.
  
      adjusted : bool, default=False
          When true, the result is adjusted for chance, so that random
          performance would score 0, while keeping perfect performance at a score
          of 1.
  
      Returns
      -------
      balanced_accuracy : float
          Balanced accuracy score.
  
      See Also
      --------
      average_precision_score : Compute average precision (AP) from prediction
          scores.
      precision_score : Compute the precision score.
      recall_score : Compute the recall score.
      roc_auc_score : Compute Area Under the Receiver Operating Characteristic
          Curve (ROC AUC) from prediction scores.
  
      Notes
      -----
      Some literature promotes alternative definitions of balanced accuracy. Our
      definition is equivalent to :func:`accuracy_score` with class-balanced
      sample weights, and shares desirable properties with the binary case.
      See the :ref:`User Guide <balanced_accuracy_score>`.
  
      References
      ----------
      .. [1] Brodersen, K.H.; Ong, C.S.; Stephan, K.E.; Buhmann, J.M. (2010).
             The balanced accuracy and its posterior distribution.
             Proceedings of the 20th International Conference on Pattern
             Recognition, 3121-24.
      .. [2] John. D. Kelleher, Brian Mac Namee, Aoife D'Arcy, (2015).
             `Fundamentals of Machine Learning for Predictive Data Analytics:
             Algorithms, Worked Examples, and Case Studies
             <https://mitpress.mit.edu/books/fundamentals-machine-learning-predictive-data-analytics>`_.
  
      Examples
      --------
      >>> from sklearn.metrics import balanced_accuracy_score
      >>> y_true = [0, 1, 0, 0, 1, 0]
      >>> y_pred = [0, 1, 0, 0, 0, 1]
      >>> balanced_accuracy_score(y_true, y_pred)
      0.625
      """
      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 warnings
  from numbers import Integral, Real
  import numpy
  from scipy.sparse import coo_matrix, csr_matrix
  from scipy.special import xlogy
  from ..exceptions import UndefinedMetricWarning
  from ..preprocessing import LabelBinarizer, LabelEncoder
  from ..utils import assert_all_finite, check_array, check_consistent_length, column_or_1d
  from ..utils._param_validation import Interval, Options, StrOptions, validate_params
  from ..utils.extmath import _nanaverage
  from ..utils.multiclass import type_of_target, unique_labels
  from ..utils.sparsefuncs import count_nonzero
  from ..utils.validation import _check_pos_label_consistency, _num_samples
label_desc: Use image node_id 20 for calling a global function with example usage: balanced_accuracy_score(y_true, y_pred) and returns: score