arviz.r2_score

arviz.r2_score(y_true, y_pred)[source]

R² for Bayesian regression models. Only valid for linear models.

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.

Returns
Pandas Series with the following indices:
r2: Bayesian R²
r2_std: standard deviation of the Bayesian R².

Examples

Calculate R² for Bayesian regression models :

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)
   ...: 
Out[1]: 
r2        0.759705
r2_std    0.005646
dtype: float64