r2_score#

cuml.metrics.r2_score(y_true, y_pred, *, sample_weight=None, multioutput='uniform_average', force_finite=True)[source]#

\(R^2\) (coefficient of determination) regression score function.

Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). In the general case when the true y is non-constant, a constant model that always predicts the average y disregarding the input features would get a \(R^2\) score of 0.0.

Parameters:
y_truearray-like of shape (n_samples,) or (n_samples, n_outputs)

Ground truth (correct) target values.

y_predarray-like of shape (n_samples,) or (n_samples, n_outputs)

Estimated target values.

sample_weightarray-like of shape (n_samples,)

Sample weights.

multioutput{‘raw_values’, ‘uniform_average’, ‘variance_weighted’} or array-like of shape (n_outputs,)

How to aggregate multioutput scores. One of:

  • ‘uniform_average’: Scores of all outputs are averaged with uniform weight. This is the default.

  • ‘variance_weighted’: Scores of all outputs are averaged, weighted by the variances of each individual output.

  • ‘raw_values’: Full set of scores in case of multioutput input.

  • array-like: Weights to use when averaging scores of all outputs.

force_finitebool, default=True

Flag indicating if NaN and -Inf scores resulting from constant data should be replaced with real numbers (1.0 if prediction is perfect, 0.0 otherwise). Default is True.

Returns:
zfloat or ndarray of floats

The \(R^2\) score or ndarray of scores if ‘multioutput’ is ‘raw_values’.