code: def r2_score(
      y_true: ArrayLike,
      y_pred: ArrayLike,
      sample_weight: Optional[ArrayLike] = None,
      multioutput: Optional[str] = "uniform_average",
      compute: bool = True,
  ) -> ArrayLike:
      _check_sample_weight(sample_weight)
      _, y_true, y_pred, _ = _check_reg_targets(
          y_true, y_pred, multioutput
      )
      weight = 1.0
  
      numerator = (weight * (y_true - y_pred) ** 2).sum(
          axis=0, dtype="f8"
      )
      denominator = (weight * (y_true - y_true.mean(axis=0)) ** 2).sum(
          axis=0, dtype="f8"
      )
  
      nonzero_denominator = denominator != 0
      nonzero_numerator = numerator != 0
      valid_score = nonzero_denominator & nonzero_numerator
      output_chunks = getattr(y_true, "chunks", [None, None])[1]
      output_scores = da.ones([y_true.shape[1]], chunks=output_chunks)
      with np.errstate(all="ignore"):
          output_scores[valid_score] = 1 - (
              numerator[valid_score] / denominator[valid_score]
          )
          output_scores[nonzero_numerator & ~nonzero_denominator] = 0.0
  
      result = output_scores.mean(axis=0)
      if compute:
          result = result.compute()
      return result
  
file_path: dask-ml/dask_ml/metrics/regression.py
imports: from typing import Optional
  import dask.array
  import numpy
  import sklearn.metrics
  from dask import is_dask_collection
  from dask.utils import derived_from
  from .._typing import ArrayLike
label_desc: Use image node_id 6 for calling a global function with example usage: r2_score(y_true, y_pred, sample_weight, multioutput, compute) and returns: result