code: def _average_multiclass_ovo_score(
      binary_metric,
      y_true,
      y_score,
      average="macro",
      session=None,
      run_kwargs=None,
  ):
      check_consistent_length(
          y_true, y_score, session=session, run_kwargs=run_kwargs
      )
  
      y_true_unique = mt.unique(y_true).to_numpy()
      n_classes = y_true_unique.shape[0]
      n_pairs = n_classes * (n_classes - 1) // 2
      pair_scores = mt.empty(n_pairs)
  
      is_weighted = average == "weighted"
      prevalence = mt.empty(n_pairs) if is_weighted else None
  
      # Compute scores treating a as positive class and b as negative class,
      # then b as positive class and a as negative class
      for ix, (a, b) in enumerate(combinations(y_true_unique, 2)):
          a_mask = y_true == a
          b_mask = y_true == b
          ab_mask = mt.logical_or(a_mask, b_mask)
  
          if is_weighted:
              prevalence[ix] = mt.average(ab_mask)
  
          a_true = a_mask[ab_mask]
          b_true = b_mask[ab_mask]
  
          a_true_score = binary_metric(a_true, y_score[ab_mask, a])
          b_true_score = binary_metric(b_true, y_score[ab_mask, b])
          pair_scores[ix] = (a_true_score + b_true_score) / 2
  
      return mt.average(pair_scores, weights=prevalence)
  
imports: from itertools import combinations
  from ...None import tensor
  from ..utils import check_array, check_consistent_length
  from ..utils.multiclass import type_of_target
label_desc: Use image node_id 2 for calling a global function with example usage: _average_multiclass_ovo_score(binary_metric, y_true, y_score, average, session, run_kwargs) and returns: mt