10000 FIX remove np.divide with where and without out argument in `precisio… · scikit-learn/scikit-learn@fb22b4f · GitHub
[go: up one dir, main page]

Skip to content

Commit fb22b4f

Browse files
lesteveogriselglemaitre
authored
FIX remove np.divide with where and without out argument in precision_recall_curve (#24382)
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org> Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
1 parent 49279c3 commit fb22b4f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sklearn/metrics/_ranking.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,10 @@ def precision_recall_curve(y_true, probas_pred, *, pos_label=None, sample_weight
871871
)
872872

873873
ps = tps + fps
874-
precision = np.divide(tps, ps, where=(ps != 0))
874+
# Initialize the result array with zeros to make sure that precision[ps == 0]
875+
# does not contain uninitialized values.
876+
precision = np.zeros_like(tps)
877+
np.divide(tps, ps, out=precision, where=(ps != 0))
875878

876879
# When no positive label in y_true, recall is set to 1 for all thresholds
877880
# tps[-1] == 0 <=> y_true == all negative labels

0 commit comments

Comments
 (0)
0