Back to questions
JuniorTheoryCommon
What does this program print?
from sklearn.metrics import precision_score, recall_score
y_true = [1, 1, 1, 1, 0, 0, 0, 0]
y_pred = [1, 1, 0, 0, 1, 0, 0, 0]
p = precision_score(y_true, y_pred)
r = recall_score(y_true, y_pred)
print(round(p, 2), round(r, 2))0.67 0.5
- Expecting
0.5 0.67, with the denominators swapped: precision divides TP by the predicted positives (2 of 3), recall by the real positives (2 of 4). - Expecting
0.62for both: that is the share of correct answers, 5 of 8, which counts both classes; precision and recall look only at class1.
- How would both values change if the model also predicted
1for the fourth sample? - Which of the two metrics matters more when a missed positive is very costly?