Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sklearn/metrics/_ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,10 @@ def precision_recall_curve(y_true, probas_pred, *, pos_label=None, sample_weight
)

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

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