Skip to content

Commit

Permalink
r2_score - add more doctest examples (scikit-learn#7727)
Browse files Browse the repository at this point in the history
Add simple examples showing perfect score, expected value score, and negative score.
  • Loading branch information
bburns authored and NelleV committed Oct 25, 2016
1 parent 7892edd commit 8f4ebb5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion sklearn/metrics/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,18 @@ def r2_score(y_true, y_pred,
>>> y_pred = [[0, 2], [-1, 2], [8, -5]]
>>> r2_score(y_true, y_pred, multioutput='variance_weighted') # doctest: +ELLIPSIS
0.938...
>>> y_true = [1,2,3]
>>> y_pred = [1,2,3]
>>> r2_score(y_true, y_pred)
1.0
>>> y_true = [1,2,3]
>>> y_pred = [2,2,2]
>>> r2_score(y_true, y_pred)
0.0
>>> y_true = [1,2,3]
>>> y_pred = [3,2,1]
>>> r2_score(y_true, y_pred)
-3.0
"""
y_type, y_true, y_pred, multioutput = _check_reg_targets(
y_true, y_pred, multioutput)
Expand Down

0 comments on commit 8f4ebb5

Please sign in to comment.