Skip to content

Commit 8f4ebb5

Browse files
bburnsNelleV
authored andcommitted
r2_score - add more doctest examples (scikit-learn#7727)
Add simple examples showing perfect score, expected value score, and negative score.
1 parent 7892edd commit 8f4ebb5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

sklearn/metrics/regression.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,18 @@ def r2_score(y_true, y_pred,
438438
>>> y_pred = [[0, 2], [-1, 2], [8, -5]]
439439
>>> r2_score(y_true, y_pred, multioutput='variance_weighted') # doctest: +ELLIPSIS
440440
0.938...
441-
441+
>>> y_true = [1,2,3]
442+
>>> y_pred = [1,2,3]
443+
>>> r2_score(y_true, y_pred)
444+
1.0
445+
>>> y_true = [1,2,3]
446+
>>> y_pred = [2,2,2]
447+
>>> r2_score(y_true, y_pred)
448+
0.0
449+
>>> y_true = [1,2,3]
450+
>>> y_pred = [3,2,1]
451+
>>> r2_score(y_true, y_pred)
452+
-3.0
442453
"""
443454
y_type, y_true, y_pred, multioutput = _check_reg_targets(
444455
y_true, y_pred, multioutput)

0 commit comments

Comments
 (0)