F1 Score of a Spam Classifier
The Larkspur Mail bake-off has come down to several filters, and the two halves of the scorecard disagree: one filter is tidier about genuine mail, another catches more spam. The panel has asked for a single score per filter so the comparison can be settled in one column - and specifically for the score that refuses to reward a filter for being excellent at one half while being poor at the other.
Every filter is scored the same way, on its own hand-labelled test run, with spam as the positive class. The four counts for a run are:
tp- spam, and the filter flagged it.fp- real mail, and the filter flagged it anyway.tn- real mail, and the filter let it through.fn- spam, and the filter let it through.
Task: Print the filter's F1 score for the spam class, as a single number rounded to 4 decimals. Round once, at the very end, not at any intermediate value.
Input
One line holding four whole numbers separated by single spaces, in the order tp fp tn fn. The filter always flags at least one email and the run always contains at least one spam.
Output
One line holding the F1 score, rounded to 4 decimals and printed the way Python prints a float - 0.8421, and 0.5 rather than 0.5000.
Example:
Input:
40 10 45 5
Output:
0.8421
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in