Thomas O'connor
Thomas O'connor

Reputation: 11

Compute accuracy from F1, precision and recall scores

During training, I forgot to save the model and the model's predictions on the test set. All I have are F1, precision, and recall scores. I was wondering if there is any way that I can compute the accuracy just from F1, precision and recall scores?

f1 = 0.9466979550787799
precision = 0.9424328383113633
recall = 0.951001852163664

Upvotes: 1

Views: 517

Answers (1)

Ash
Ash

Reputation: 4718

The short answer is that you have three equations but four variables, so you can but only if you already know the total number of elements you have made predictions for. To see that in detail, let's note true positives, true negatives, false positives and false negatives as (respectively) TP, TN, FP, FN.

From the definition of precision as TP/(TP+FP), you can get

FP=TP(1-precision)/precision   (1)

and similarly, from the definition of recall, you will get

FN=TP(1-recall)/recall         (2)

Now let's use the definition of F1 score as F1=2/(precision^{-1}+recall^{-1}). By plugging in the FN and FP expressions from above, we'll get to the following expression:

F1=2TP / (2TP +TP(1-recall)/recall + TP(1-prec)/prec)

You can easily solve this equation and get the value of TP. Plugging this into (1) and (2), you will have reached a point where you know TP, FN, FP.

You still need to know the true negative TN in order to compute accuracy (assuming that you go by the usual definition of accuracy as (TP+TN)/(TP+TN+FP+FN)).

To determine TN, you need to know the total number of elements total_n:

TN=total_n - (TP+FN+FP)

Once you know that you can compute the accuracy.

Upvotes: 1

Related Questions