code: def r2_score(y_true, y_pred):
      """R² for Bayesian regression models. Only valid for linear models.
  
      Parameters
      ----------
      y_true: array-like of shape = (n_outputs,)
          Ground truth (correct) target values.
      y_pred: array-like of shape = (n_posterior_samples, n_outputs)
          Estimated target values.
  
      Returns
      -------
      Pandas Series with the following indices:
      r2: Bayesian R²
      r2_std: standard deviation of the Bayesian R².
  
      See Also
      --------
      plot_lm : Posterior predictive and mean plots for regression-like data.
  
      Examples
      --------
      Calculate R² for Bayesian regression models :
  
      .. ipython::
  
          In [1]: import arviz as az
             ...: data = az.load_arviz_data('regression1d')
             ...: y_true = data.observed_data["y"].values
             ...: y_pred = data.posterior_predictive.stack(sample=("chain", "draw"))["y"].values.T
             ...: az.r2_score(y_true, y_pred)
  
      """
      r_squared = r2_samples(y_true=y_true, y_pred=y_pred)
      return pd.Series(
          [np.mean(r_squared), np.std(r_squared)],
          index=["r2", "r2_std"],
      )
  
imports: import itertools
  import warnings
  from copy import deepcopy
  from typing import List, Optional, Tuple, Union, Mapping, cast, Callable
  import numpy
  import pandas
  import scipy.stats
  from xarray_einstats import stats
  import xarray
  from scipy.optimize import minimize
  from typing_extensions import Literal
  from ..None import _log
  from ..data import InferenceData, convert_to_dataset, convert_to_inference_data, extract
  from ..rcparams import rcParams, ScaleKeyword, ICKeyword
  from ..utils import Numba, _numba_var, _var_names, get_coords
  from .density_utils import get_bins
  from .density_utils import histogram
  from .density_utils import kde
  from .diagnostics import _mc_error, _multichain_statistics, ess
  from .stats_utils import ELPDData, _circular_standard_deviation, smooth_data
  from .stats_utils import get_log_likelihood
  from .stats_utils import get_log_prior
  from .stats_utils import logsumexp
  from .stats_utils import make_ufunc
  from .stats_utils import stats_variance_2d
  from .stats_utils import wrap_xarray_ufunc
  from ..sel_utils import xarray_var_iter
  from ..labels import BaseLabeller
label_desc: Use image node_id 13 for calling a global function with example usage: r2_score(y_true, y_pred) and returns: pd