All problems

Accuracy of a Spam Classifier

easyPythonML Metrics

Larkspur Mail has finished testing a new spam filter and the summary slide needs one headline number. The filter was pointed at a set of test emails that a person had already read and labelled by hand, so for every email there is a human verdict to check the machine against.

In this evaluation the positive class is spam. "Positive" only means the filter raised the alarm; it does not mean anything good happened. That gives four counts, and every test email falls into exactly one of them:

  • 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.

The same slide is produced for every filter the team trials, on test sets of different sizes and very different spam mixes, so the four counts arrive as data.

Task: Print the filter's accuracy, measured across the whole test set rather than within either class on its own. Print the raw number - no rounding is asked for.

Input

One line holding four whole numbers separated by single spaces, in the order tp fp tn fn. They are never all zero.

Output

One line holding the accuracy as a float, printed raw - 0.85, and 0.6666666666666666 when the division does not terminate.

Example:

Input:
40 10 45 5

Output:
0.85

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

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…