Precision and RecallCode with Python
scikit-learn has a function for every score in this chapter. Suppose the camp's results are saved in a file, dengue_camp.csv, with one row per person: the test score, and whether the lab found dengue (1) or not (0). Comparing each score with the threshold gives the test's answers, y_pred.
Look closely at the printed matrix: scikit-learn puts the negatives first, so its top row is the healthy people (TN, FP) and its bottom row the patients (FN, TP). Run the program, then try another threshold.
Counting by Hand
Without a library, the four boxes are just four counters. Here are 12 people from the camp. For each person the loop asks two questions — did the test say positive, and did they really have dengue? — and adds 1 to the right box. Run it, then change the threshold.