code: def d2_pinball_score(
      y_true,
      y_pred,
      *,
      sample_weight=None,
      alpha=0.5,
      multioutput="uniform_average",
  ):
      """
      :math:`D^2` regression score function, fraction of pinball loss explained.
  
      Best possible score is 1.0 and it can be negative (because the model can be
      arbitrarily worse). A model that always uses the empirical alpha-quantile of
      `y_true` as constant prediction, disregarding the input features,
      gets a :math:`D^2` score of 0.0.
  
      Read more in the :ref:`User Guide <d2_score>`.
  
      .. versionadded:: 1.1
  
      Parameters
      ----------
      y_true : array-like of shape (n_samples,) or (n_samples, n_outputs)
          Ground truth (correct) target values.
  
      y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs)
          Estimated target values.
  
      sample_weight : array-like of shape (n_samples,), default=None
          Sample weights.
  
      alpha : float, default=0.5
          Slope of the pinball deviance. It determines the quantile level alpha
          for which the pinball deviance and also D2 are optimal.
          The default `alpha=0.5` is equivalent to `d2_absolute_error_score`.
  
      multioutput : {'raw_values', 'uniform_average'} or array-like of shape \
              (n_outputs,), default='uniform_average'
          Defines aggregating of multiple output values.
          Array-like value defines weights used to average scores.
  
          'raw_values' :
              Returns a full set of errors in case of multioutput input.
  
          'uniform_average' :
              Scores of all outputs are averaged with uniform weight.
  
      Returns
      -------
      score : float or ndarray of floats
          The :math:`D^2` score with a pinball deviance
          or ndarray of scores if `multioutput='raw_values'`.
  
      Notes
      -----
      Like :math:`R^2`, :math:`D^2` score may be negative
      (it need not actually be the square of a quantity D).
  
      This metric is not well-defined for a single point and will return a NaN
      value if n_samples is less than two.
  
       References
      ----------
      .. [1] Eq. (7) of `Koenker, Roger; Machado, José A. F. (1999).
             "Goodness of Fit and Related Inference Processes for Quantile Regression"
             <https://doi.org/10.1080/01621459.1999.10473882>`_
      .. [2] Eq. (3.11) of Hastie, Trevor J., Robert Tibshirani and Martin J.
             Wainwright. "Statistical Learning with Sparsity: The Lasso and
             Generalizations." (2015). https://hastie.su.domains/StatLearnSparsity/
  
      Examples
      --------
      >>> from sklearn.metrics import d2_pinball_score
      >>> y_true = [1, 2, 3]
      >>> y_pred = [1, 3, 3]
      >>> d2_pinball_score(y_true, y_pred)
      0.5
      >>> d2_pinball_score(y_true, y_pred, alpha=0.9)
      0.772...
      >>> d2_pinball_score(y_true, y_pred, alpha=0.1)
      -1.045...
      >>> d2_pinball_score(y_true, y_true, alpha=0.1)
      1.0
      """
      y_type, y_true, y_pred, multioutput = _check_reg_targets(
          y_true, y_pred, multioutput
      )
      check_consistent_length(y_true, y_pred, sample_weight)
  
      if _num_samples(y_pred) < 2:
          msg = "D^2 score is not well-defined with less than two samples."
          warnings.warn(msg, UndefinedMetricWarning)
          return float("nan")
  
      numerator = mean_pinball_loss(
          y_true,
          y_pred,
          sample_weight=sample_weight,
          alpha=alpha,
          multioutput="raw_values",
      )
  
      if sample_weight is None:
          y_quantile = np.tile(
              np.percentile(y_true, q=alpha * 100, axis=0),
              (len(y_true), 1),
          )
      else:
          sample_weight = _check_sample_weight(sample_weight, y_true)
          y_quantile = np.tile(
              _weighted_percentile(
                  y_true,
                  sample_weight=sample_weight,
                  percentile=alpha * 100,
              ),
              (len(y_true), 1),
          )
  
      denominator = mean_pinball_loss(
          y_true,
          y_quantile,
          sample_weight=sample_weight,
          alpha=alpha,
          multioutput="raw_values",
      )
  
      nonzero_numerator = numerator != 0
      nonzero_denominator = denominator != 0
      valid_score = nonzero_numerator & nonzero_denominator
      output_scores = np.ones(y_true.shape[1])
  
      output_scores[valid_score] = 1 - (
          numerator[valid_score] / denominator[valid_score]
      )
      output_scores[nonzero_numerator & ~nonzero_denominator] = 0.0
  
      if isinstance(multioutput, str):
          if multioutput == "raw_values":
              # return scores individually
              return output_scores
          else:  # multioutput == "uniform_average"
              # passing None as weights to np.average results in uniform mean
              avg_weights = None
      else:
          avg_weights = multioutput
  
      return np.average(output_scores, weights=avg_weights)
  
imports: import warnings
  from numbers import Real
  import numpy
  from scipy.special import xlogy
  from ..exceptions import UndefinedMetricWarning
  from ..utils._param_validation import Hidden, Interval, StrOptions, validate_params
  from ..utils.stats import _weighted_percentile
  from ..utils.validation import _check_sample_weight, _num_samples, check_array, check_consistent_length, column_or_1d
label_desc: Use image node_id 19 for calling a global function with example usage: d2_pinball_score(y_true, y_pred) and returns: np, float, output_scores