Change language

Statistics

Precision, recall and F1 calculator

Classification metrics from a confusion matrix.

Published by SolucionesAhora.com How we verify

Calculator inputs

Results

Enter your values and press “Calculate” to see the result.

Free, no sign-up! What if you could do this without a calculator? A five-minute game with challenges, lives and points. It clicks even when you cannot be bothered.

In short

What it calculates
Classification metrics from a confusion matrix.
Formula used
Precision = TP / (TP + FP)
Example
TP = 80, FP = 20, FN = 15, TN = 85:

Precision, recall and F1 calculator

These are the metrics used to evaluate any classifier, from a machine learning model to a diagnostic test.

Enter the four confusion matrix values and get all five metrics at once.

How it works

Precision answers “of what I flagged as positive, how much actually was”; recall answers “of everything that was positive, how much did I catch”. F1 is their harmonic mean and penalises imbalance.

Formula

Precision = TP / (TP + FP)

Recall = TP / (TP + FN)

F1 = 2 · (precision · recall) / (precision + recall)

Accuracy = (TP + TN) / total
Specificity = TN / (TN + FP)

Worked example

TP = 80, FP = 20, FN = 15, TN = 85:

Precision: 80%
Recall: 84.2%
F1: 82.1%
Accuracy: 82.5%

Explanation

Precision and recall pull in opposite directions

A model that only flags cases it is certain about will have very high precision and miss many. One that flags almost everything will capture nearly all positives with terrible precision. Adjusting the threshold moves the balance between them, and deciding where to set it is a business decision, not a technical one.

Which to prioritise depends on the cost of the error

In medical screening, missing a case is far worse than a false alarm, so recall takes priority. In a spam filter, marking a legitimate message as junk is worse than letting advertising through, so precision takes priority. There is no universal answer.

Why F1 uses the harmonic mean

The arithmetic mean rewards extremes: a model with a hundred per cent precision and zero recall would score fifty. The harmonic mean punishes imbalance and gives zero in that case, which is reasonable. That is why F1 is only high when both metrics are.

Accuracy misleads with imbalanced classes

If only one per cent of cases are positive, a model that always answers no is right ninety-nine per cent of the time while detecting nothing. It is why accuracy is a useless metric in fraud detection or rare disease screening.

Frequently asked questions

Why does F1 use the harmonic mean?

Because it punishes low values: with 100% precision and 10% recall, the arithmetic mean would be 55% but F1 is only 18%.

Do I need true negatives?

Only for accuracy and specificity. Precision, recall and F1 are computed without them.

Why does F1 use the harmonic mean?

Because it punishes imbalance. With a hundred per cent precision and zero recall, the arithmetic mean would give fifty while the harmonic gives zero, which reflects reality better.

Why is accuracy not enough?

With imbalanced classes it misleads: if only one per cent are positive, always answering no is right ninety-nine per cent of the time while detecting nothing.

Need to calculate something else?

These tools are often used alongside this calculator.

Chi-square

Chi-square test for contingency tables and goodness of fit, with Cramér’s V, residuals, Yates’ correction…

Sample size

How many responses you need to estimate a percentage or a mean, with finite population, design effect and…

Pearson correlation

Pearson’s r between two variables, with p value, confidence interval, regression line and scatter plot.

t-test

Compare two means (independent or paired) or one mean with a value, with p value, confidence interval and…