Found and Flagged
A test flags people as sick (1) or well (0). truth holds who really is sick and guess who was flagged. Return [precision, recall]: the share of the flagged who really are sick, and the share of the sick who were flagged.
Example 1
truth [1,1,1,0,0,0]
guess [1,1,0,1,0,0]
returns [0.6666666666666666,0.6666666666666666]
Three were flagged and two of them are sick. Three are sick and two of them were flagged.
Example 2
truth [1,0]
guess [1,1]
returns [0.5,1.0]
Everyone was flagged, so the one sick person was found, but only half of the flags were right.
Constraints
2 <= len(truth) <= 60- At least one person is sick and at least one is flagged
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.