ageron / ageron/handson-ml2

Ch3_PrecisionScore/Recall_score _ Zero division problem

Open
#257 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
30k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

I tried running this code:

# If we set a threshold of 70000 based on some precision criteria (say around 90%)
y_train_pred_90 = (y_scores > 70000)

from sklearn.metrics import precision_score, recall_score

print(precision_score(y_train_5, y_train_pred_90))) # output?: 0
#UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 due to no predicted samples. Use `zero_division`
parameter to control this behavior.

recall_score(y_train_5, y_train_pred_90) # returning 0

# https://github.com/scikit-learn/scikit-learn/issues/14876#issuecomment-527879372
# https://stackoverflow.com/a/47285662/5114585

I understand that sometimes denominator becomes zero and we get these warnings & we can set default value to be 0 or 1 [https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html]

My questions:
1. My results are not matching from the book [below results from book].

>>> precision_score(y_train_5, y_train_pred_90)
0.8998702983138781
>>> recall_score(y_train_5, y_train_pred_90)
0.63991883416343853

2. Better ways to handle this issue?
Setting different threshold, ignoring the labels which were not predicted [https://stackoverflow.com/a/47285662/5114585](url)
something else?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.