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_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².
    """
    if y_pred.ndim == 1:
        var_y_est = np.var(y_pred)
        var_e = np.var(y_true - y_pred)
    else:
        var_y_est = np.var(y_pred.mean(0))
        var_e = np.var(y_true - y_pred, 0)

    r_squared = var_y_est / (var_y_est + var_e)

    return pd.Series([np.mean(r_squared), np.std(r_squared)], index=["r2", "r2_std"])
def r2_score ( y_true , y_pred ) : if y_pred . ndim == 1 : var_y_est = np . var ( y_pred ) var_e = np . var ( y_true - y_pred ) else : var_y_est = np . var ( y_pred . mean ( 0 ) ) var_e = np . var ( y_true - y_pred , 0 ) r_squared = var_y_est / ( var_y_est + var_e ) return pd . Series ( [ np . mean ( r_squared ) , np . std ( r_squared ) ] , index = [ "r2" , "r2_std" ] )
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².