How to calculate Precision and recall in the testdataloader loop for the entire dataset?
You cannot calculate precision and recall directly at the minibatch level and aggregate then, but you have to decide for each item in the minibatch whether it is true positive, false positive, true negative, or false negative.
After accumulating the counts of those four over your dataset (i.e. doing loop of minibatches from your dataloader) you calculate precision = true_positives / (true_positives + false_positives
) and recall = true_postivies / (true_positives + false_negatives)
.
Best regards
Thomas
I have create a confusion numpy matrix from that i need to calculate these tp fp tn fn how to do that i want to calculate precision over all classes
If you have two classes, tp, tf, tn, fn are just from the four ways to have prediction / target.
If you have more classes, you usually get a per class precision/recall (by taking a one-vs-all approach).
Best regards
Thomas
So in multi class there is no way to calculate overall precesion and recall