sklearn.metrics.r2_score¶
- sklearn.metrics.r2_score(y_true, y_pred, sample_weight=None)¶
R^2 (coefficient of determination) regression score function.
Best possible score is 1.0, lower values are worse.
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.
sample_weight : array-like of shape = [n_samples], optional
Sample weights.
Returns: z : float
The R^2 score.
Notes
This is not a symmetric function.
Unlike most other scores, R^2 score may be negative (it need not actually be the square of a quantity R).
References
[R168] Wikipedia entry on the Coefficient of determination Examples
>>> from sklearn.metrics import r2_score >>> y_true = [3, -0.5, 2, 7] >>> y_pred = [2.5, 0.0, 2, 8] >>> r2_score(y_true, y_pred) 0.948... >>> y_true = [[0.5, 1], [-1, 1], [7, -6]] >>> y_pred = [[0, 2], [-1, 2], [8, -5]] >>> r2_score(y_true, y_pred) 0.938...