I am trying to implement the F1 score shown here in Python.
The inputs for my function are a list of predictions and a list of actual correct values. I thought that the most efficient way of calculating the number of true positive, false negatives and false positives would be to convert the two lists into two sets then use set intersection and differences to find the quantities of interest. Here is my code
To compute the length of a set difference, you only need to subtract the length of the intersection from the length of the set.
You could make use of the intersection when computing the differences. Subtracting the intersection gives the same result but processes fewer elements.