8000 [MRG] Fix the element-wise comparison error thrown by numpy. · scikit-learn/scikit-learn@019f892 · GitHub
[go: up one dir, main page]

Skip to content

Commit 019f892

Browse files
committed
[MRG] Fix the element-wise comparison error thrown by numpy.
* Refactored the if clause and add proper check for valid strings. * Fix PEP8 errors.
1 parent b7a1ad2 commit 019f892

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sklearn/metrics/regression.py

Lines c DEF6 hanged: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ def _check_reg_targets(y_true, y_pred, multioutput):
9090
n_outputs = y_true.shape[1]
9191
multioutput_options = (None, 'raw_values', 'uniform_average',
9292
'variance_weighted')
93-
if multioutput not in multioutput_options:
93+
if isinstance(multioutput, string_types) and \
94+
multioutput not in multioutput_options:
95+
raise ValueError("Invalid multioutput option")
96+
97+
elif multioutput is not None and not isinstance(multioutput, string_types):
9498
multioutput = check_array(multioutput, ensure_2d=False)
9599
if n_outputs == 1:
96100
raise ValueError("Custom weights are useful only in "
@@ -505,7 +509,8 @@ def r2_score(y_true, y_pred,
505509
0.948...
506510
>>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
507511
>>> y_pred = [[0, 2], [-1, 2], [8, -5]]
508-
>>> r2_score(y_true, y_pred, multioutput='variance_weighted') # doctest: +ELLIPSIS
512+
# doctest: +ELLIPSIS
513+
>>> r2_score(y_true, y_pred, multioutput='variance_weighted')
509514
0.938...
510515
>>> y_true = [1,2,3]
511516
>>> y_pred = [1,2,3]

0 commit comments

Comments
 (0)
0