code: def roc_curve(
      y_true,
      y_score,
      pos_label=None,
      sample_weight=None,
      drop_intermediate=True,
      session=None,
      run_kwargs=None,
  ):
      """Compute Receiver operating characteristic (ROC)
  
      Note: this implementation is restricted to the binary classification task.
  
      Read more in the :ref:`User Guide <roc_metrics>`.
  
      Parameters
      ----------
  
      y_true : tensor, shape = [n_samples]
          True binary labels. If labels are not either {-1, 1} or {0, 1}, then
          pos_label should be explicitly given.
  
      y_score : tensor, shape = [n_samples]
          Target scores, can either be probability estimates of the positive
          class, confidence values, or non-thresholded measure of decisions
          (as returned by "decision_function" on some classifiers).
  
      pos_label : int or str, default=None
          The label of the positive class.
          When ``pos_label=None``, if y_true is in {-1, 1} or {0, 1},
          ``pos_label`` is set to 1, otherwise an error will be raised.
  
      sample_weight : array-like of shape (n_samples,), default=None
          Sample weights.
  
      drop_intermediate : boolean, optional (default=True)
          Whether to drop some suboptimal thresholds which would not appear
          on a plotted ROC curve. This is useful in order to create lighter
          ROC curves.
  
          .. versionadded:: 0.17
             parameter *drop_intermediate*.
  
      Returns
      -------
      fpr : tensor, shape = [>2]
          Increasing false positive rates such that element i is the false
          positive rate of predictions with score >= thresholds[i].
  
      tpr : tensor, shape = [>2]
          Increasing true positive rates such that element i is the true
          positive rate of predictions with score >= thresholds[i].
  
      thresholds : tensor, shape = [n_thresholds]
          Decreasing thresholds on the decision function used to compute
          fpr and tpr. `thresholds[0]` represents no instances being predicted
          and is arbitrarily set to `max(y_score) + 1`.
  
      See also
      --------
      roc_auc_score : Compute the area under the ROC curve
  
      Notes
      -----
      Since the thresholds are sorted from low to high values, they
      are reversed upon returning them to ensure they correspond to both ``fpr``
      and ``tpr``, which are sorted in reversed order during their calculation.
  
      References
      ----------
      .. [1] `Wikipedia entry for the Receiver operating characteristic
              <https://en.wikipedia.org/wiki/Receiver_operating_characteristic>`_
  
      .. [2] Fawcett T. An introduction to ROC analysis[J]. Pattern Recognition
             Letters, 2006, 27(8):861-874.
  
      Examples
      --------
      >>> import mars.tensor as mt
      >>> from mars.learn import metrics
      >>> y = mt.array([1, 1, 2, 2])
      >>> scores = mt.array([0.1, 0.4, 0.35, 0.8])
      >>> fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2)
      >>> fpr
      array([0. , 0. , 0.5, 0.5, 1. ])
      >>> tpr
      array([0. , 0.5, 0.5, 1. , 1. ])
      >>> thresholds
      array([1.8 , 0.8 , 0.4 , 0.35, 0.1 ])
  
      """
      from sklearn.exceptions import UndefinedMetricWarning
  
      cache_tileables(y_true, y_score)
  
      fps, tps, thresholds = _binary_clf_curve(
          y_true,
          y_score,
          pos_label=pos_label,
          sample_weight=sample_weight,
          session=session,
          run_kwargs=run_kwargs,
      )
  
      # Attempt to drop thresholds corresponding to points in between and
      # collinear with other points. These are always suboptimal and do not
      # appear on a plotted ROC curve (and thus do not affect the AUC).
      # Here mt.diff(_, 2) is used as a "second derivative" to tell if there
      # is a corner at the point. Both fps and tps must be tested to handle
      # thresholds with multiple data points (which are combined in
      # _binary_clf_curve). This keeps all cases where the point should be kept,
      # but does not drop more complicated cases like fps = [1, 3, 7],
      # tps = [1, 2, 4]; there is no harm in keeping too many thresholds.
      if drop_intermediate and len(fps) > 2:
          optimal_idxs = mt.where(
              mt.r_[
                  True,
                  mt.logical_or(mt.diff(fps, 2), mt.diff(tps, 2)),
                  True,
              ]
          )[0]
          # original implementation of sklearn:
          # """
          # fps = fps[optimal_idxs]
          # tps = tps[optimal_idxs]
          # thresholds = thresholds[optimal_idxs]
          # """
          # however, it's really a heavy operation to perform fancy index,
          # thus we put them together
          stacked = mt.stack([fps, tps, thresholds])
          fps, tps, thresholds = stacked[:, optimal_idxs]
  
      # Add an extra threshold position
      # to make sure that the curve starts at (0, 0)
      tps = mt.r_[0, tps]
      fps = mt.r_[0, fps]
      thresholds = mt.r_[thresholds[0] + 1, thresholds]
  
      last_fps = fps[-1]
      last_tps = tps[-1]
      _execute(
          [tps, fps, last_fps, last_tps, thresholds],
          session=session,
          **(run_kwargs or dict()),
      )
      last_fps, last_tps = _fetch([last_fps, last_tps], session=session)
  
      if last_fps <= 0:
          warnings.warn(
              "No negative samples in y_true, "
              "false positive value should be meaningless",
              UndefinedMetricWarning,
          )
          fpr = mt.repeat(mt.nan, fps.shape)
      else:
          fpr = fps / last_fps
  
      if last_tps <= 0:
          warnings.warn(
              "No positive samples in y_true, "
              "true positive value should be meaningless",
              UndefinedMetricWarning,
          )
          tpr = mt.repeat(mt.nan, tps.shape)
      else:
          tpr = tps / last_tps
  
      ret = mt.ExecutableTuple([fpr, tpr, thresholds]).execute(
          session=session, **(run_kwargs or dict())
      )
      return ret
  
file_path: mars/mars/learn/metrics/_ranking.py
imports: import warnings
  from functools import partial
  import numpy
  from ...None import execute, fetch
  from ...None import tensor
  from ...utils import cache_tileables
  from ..preprocessing import label_binarize
  from ..utils._encode import _encode, _unique
  from ..utils.checks import assert_all_finite
  from ..utils.core import sort_by
  from ..utils.multiclass import type_of_target
  from ..utils.validation import check_array, check_consistent_length, column_or_1d
  from ._base import _average_binary_score, _average_multiclass_ovo_score
label_desc: Use image node_id 6 for calling a global function with example usage: roc_curve(y_true, y_score, pos_label, sample_weight, drop_intermediate, session, run_kwargs) and returns: ret