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_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
ofthe
Bayesian
R².
See also
plot_lm
Posterior predictive and mean plots for regression-like data.
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.683197 r2_std 0.036884 dtype: float64