# Confusion matrix Pt : 2

# Precision, Recall and F1-Score Explained Like You’re 5

In the last article, we talked about the **Confusion Matrix**.

We learned that a classification model can make four kinds of decisions:

```text
True Positive
True Negative
False Positive
False Negative
```

Now the next question is:

> How do we use these four numbers to understand whether our model is actually good?

This is where **Precision, Recall, and F1-Score** come in.

They may look like scary formulas at first.

But the ideas are actually very simple.

* * *

# Let's Use a Simple Fraud Example

Imagine our ML model checks 100 transactions.

Out of those, the model says:

> “These 10 transactions are fraud.”

Now we check what really happened.

Out of those 10:

*   8 were actually fraud
    
*   2 were normal transactions
    

And there were also 2 fraud transactions that the model completely missed.

So our confusion matrix numbers are:

```text
TP = 8
FP = 2
FN = 2
TN = 88
```

Now we can understand Precision, Recall, and F1.

* * *

# What Is Precision?

Precision asks a very simple question:

> Out of everything the model called fraud, how much was actually fraud?

Our model called 10 transactions fraud.

Out of those 10, only 8 were really fraud.

So:

\[ Precision = \\frac{TP}{TP + FP} \]

For our example:

\[ Precision = \\frac{8}{8 + 2} \]

\[ Precision = \\frac{8}{10} = 0.8 \]

So:

\[ Precision = 80% \]

In simple words:

> When the model says “Fraud”, it is correct 80% of the time.

* * *

# Think of Precision Like a Police Officer

Imagine a police officer stops 10 people because he thinks they are thieves.

Later we find out only 8 of them were actually thieves.

The other 2 were innocent.

That means the officer had some **false alarms**.

Precision tells us:

> How often was the officer correct when he accused someone?

High Precision means:

```text
Very few false alarms
```

Low Precision means:

```text
The model keeps accusing innocent cases
```

* * *

# When Is Precision Important?

Precision matters when **false positives are expensive**.

For example:

*   Email spam detection
    
*   Fraud blocking
    
*   Medical diagnosis in some cases
    
*   Content moderation
    

Imagine your banking app blocks too many normal transactions.

Even if the system catches fraud, customers may become angry because their genuine payments are also being blocked.

In that case, Precision becomes important.

* * *

# Now What Is Recall?

Recall asks a different question:

> Out of all the real fraud cases, how many did the model actually catch?

We had:

```text
8 frauds caught correctly
2 frauds missed
```

So the total real fraud cases were:

```text
8 + 2 = 10
```

The formula is:

\[ Recall = \\frac{TP}{TP + FN} \]

For our example:

\[ Recall = \\frac{8}{8 + 2} \]

\[ Recall = \\frac{8}{10} = 0.8 \]

So:

\[ Recall = 80% \]

This means:

> The model caught 80% of all the fraud cases.

* * *

# Think of Recall Like Catching Fish

Imagine there are 10 fish in a pond.

You catch 8.

You miss 2.

Your recall is:

\[ \\frac{8}{10} = 80% \]

Recall is about:

> How much of the important stuff did you manage to catch?

High Recall means:

```text
You miss very few real positive cases
```

Low Recall means:

```text
Many important cases slip through
```

* * *

# When Is Recall Important?

Recall matters when **missing a positive case is dangerous**.

Examples:

*   Fraud detection
    
*   Cancer detection
    
*   Security threat detection
    
*   Fire detection
    
*   Fault detection in machines
    

Imagine a fraud model has:

```text
Precision = 95%
Recall = 30%
```

That means whenever it says fraud, it is usually right.

Sounds good.

But it only catches 30% of all fraud.

So 70% of fraud still passes through.

That is a serious problem.

This is why one metric alone is not enough.

* * *

# Precision vs Recall

This is one of the most important ideas in classification.

Precision asks:

> When I say YES, how often am I right?

Recall asks:

> Out of all the real YES cases, how many did I find?

Very simple.

```text
Precision → Are my positive predictions correct?

Recall → Did I find most of the real positives?
```

* * *

# A Small Example

Imagine a model detects sick patients.

There are actually 10 sick people.

The model says 6 people are sick.

Out of those 6:

```text
5 are actually sick
1 is healthy
```

It missed 5 other sick people.

So:

```text
TP = 5
FP = 1
FN = 5
```

Precision:

\[ Precision = \\frac{5}{5+1} \]

\[ Precision \\approx 0.83 \]

So:

\[ Precision \\approx 83% \]

Recall:

\[ Recall = \\frac{5}{5+5} \]

\[ Recall = 0.5 \]

So:

\[ Recall = 50% \]

The model looks pretty accurate when it predicts someone is sick.

But it misses half of the real sick patients.

This is why Recall matters.

* * *

# So What Is F1-Score?

Now we have a problem.

Sometimes Precision is good and Recall is bad.

Sometimes Recall is good and Precision is bad.

We need one number that considers both.

That number is called the **F1-Score**.

The formula is:

\[ F1 = 2 \\times \\frac{Precision \\times Recall}{Precision + Recall} \]

It looks complicated.

But the idea is simple.

F1 asks:

> Are Precision and Recall both reasonably good?

* * *

# Let's Calculate F1

Suppose:

\[ Precision = 0.8 \]

and:

\[ Recall = 0.6 \]

Then:

\[ F1 = 2 \\times \\frac{0.8 \\times 0.6}{0.8 + 0.6} \]

First:

\[ 0.8 \\times 0.6 = 0.48 \]

Then:

\[ 0.8 + 0.6 = 1.4 \]

So:

\[ F1 = 2 \\times \\frac{0.48}{1.4} \]

\[ F1 \\approx 0.686 \]

So:

\[ F1 \\approx 68.6% \]

* * *

# Why Don't We Just Take the Normal Average?

You may think:

> Why not simply do this?

\[ \\frac{Precision + Recall}{2} \]

Good question.

F1 uses something called the **harmonic mean**.

You do not need to be scared by the name.

The useful idea is:

> F1 punishes imbalance between Precision and Recall.

For example:

```text
Precision = 100%
Recall = 10%
```

A normal average would give:

```text
55%
```

That can look better than the model really is.

But F1 becomes much lower.

That tells us:

> One side is very weak.

This is why F1 is useful.

* * *

# Think of F1 Like Two Wheels on a Bicycle

Imagine Precision is one wheel.

Recall is the other wheel.

If one wheel is perfect but the other wheel is broken, the bicycle is still not going to work properly.

F1 checks both wheels together.

```text
Good Precision + Good Recall
              ↓
          Good F1
```

* * *

# Precision, Recall and F1 Together

Here is the easiest way I remember them:

```text
Precision:
When the model says YES,
how often is it correct?

Recall:
Out of all the real YES cases,
how many did the model find?

F1:
Are Precision and Recall
both reasonably good?
```

* * *

# Another Fraud Example

Suppose:

```text
TP = 90
FP = 10
FN = 30
```

Precision:

\[ Precision = \\frac{90}{90+10} \]

\[ Precision = 0.90 \]

So:

```text
Precision = 90%
```

Recall:

\[ Recall = \\frac{90}{90+30} \]

\[ Recall = 0.75 \]

So:

```text
Recall = 75%
```

Now F1:

\[ F1 = 2 \\times \\frac{0.90 \\times 0.75}{0.90+0.75} \]

\[ F1 \\approx 0.818 \]

So:

```text
F1 ≈ 81.8%
```

Now we have a much better picture of the model.

* * *

# Can We Always Say Higher F1 Means Better?

Not always.

Metrics depend on the problem.

For example, in fraud detection, maybe missing fraud is extremely expensive.

Then Recall may be more important.

In another problem, false alarms may be very expensive.

Then Precision may matter more.

So we should never choose a metric without thinking about the business problem.

* * *

# Accuracy vs Precision vs Recall vs F1

Here is the simplest summary:

```text
Accuracy
→ How often was the model correct overall?

Precision
→ When it predicted positive, how often was it right?

Recall
→ How many real positives did it find?

F1
→ Is there a good balance between Precision and Recall?
```

* * *

# One Important Thing: Thresholds

Many classification models do not directly say:

```text
Fraud
Not Fraud
```

They first give a probability.

For example:

```text
Fraud Probability = 0.72
```

Then we choose a threshold.

Maybe:

```text
Probability >= 0.50
→ Fraud
```

But if we change the threshold:

```text
Probability >= 0.80
→ Fraud
```

Precision and Recall can change.

Usually:

```text
Higher threshold
→ Fewer fraud predictions
→ Precision may increase
→ Recall may decrease
```

And:

```text
Lower threshold
→ More fraud predictions
→ Recall may increase
→ Precision may decrease
```

This is called the **Precision-Recall trade-off**.

It is one of the most important ideas in real classification systems.

* * *

# Final Thought

When I first saw Precision, Recall, and F1, they looked like three more formulas I had to remember.

But once I started asking what each one actually means, they became much easier.

Precision asks:

> Are my positive predictions trustworthy?

Recall asks:

> Am I catching enough of the real positive cases?

F1 asks:

> Are Precision and Recall working well together?

The formulas matter.

But understanding the question behind the formula matters even more.

That is how I personally like to learn Machine Learning.

## How Precision, Recall, and F1 Depend on Each Other

These three metrics are connected.

The easiest way to understand it is through the classification threshold.

Imagine the model gives this score:

```text
Fraud Probability = 0.72
```

If our threshold is:

```text
0.50
```

the model says:

> Fraud.

But if we increase the threshold to:

```text
0.80
```

the same transaction is now considered normal.

So changing the threshold changes how many positive predictions the model makes.

* * *

### If We Lower the Threshold

The model becomes more aggressive.

It says “YES” more often.

For fraud detection, that means it tries to catch more fraud cases.

So:

```text
Lower Threshold
      ↓
More Positive Predictions
      ↓
Usually Higher Recall
      ↓
But More False Positives
      ↓
Precision May Decrease
```

Why?

Because the model catches more real fraud, but it may also incorrectly flag more normal transactions.

* * *

### If We Increase the Threshold

Now the model becomes more careful.

It only says “YES” when it is very confident.

So:

```text
Higher Threshold
      ↓
Fewer Positive Predictions
      ↓
Usually Higher Precision
      ↓
But More Fraud Can Be Missed
      ↓
Recall May Decrease
```

So Precision and Recall often behave like a seesaw.

```text
Precision ↑
Recall    ↓

or

Recall    ↑
Precision ↓
```

This is called the **Precision-Recall trade-off**.

* * *

## Where Does F1 Come In?

F1 depends directly on Precision and Recall.

The formula is:

\[ F1 = 2 \\times \\frac{Precision \\times Recall}{Precision + Recall} \]

So if one of them becomes very weak, F1 also drops.

For example:

```text
Precision = 95%
Recall = 20%
```

Even though Precision looks excellent, the model is missing too many real positive cases.

F1 will reflect that imbalance.

Now imagine:

```text
Precision = 85%
Recall = 82%
```

Both are reasonably strong.

The F1-score will also be strong.

So F1 is basically asking:

> Are Precision and Recall both healthy at the same time?

* * *

## Think of It Like a Seesaw

Imagine Precision is sitting on one side.

Recall is sitting on the other side.

If we move the classification threshold, the balance changes.

```text
        Precision
            ↑
            |
         Threshold
            |
            ↓
          Recall
```

F1 watches both sides.

It gives us one number that tells us whether the balance between Precision and Recall is reasonable.

* * *

## One Important Point

We should not try to maximize Precision, Recall, and F1 blindly.

The correct balance depends on the problem.

In fraud detection:

> Missing fraud may be more expensive than checking a few extra transactions.

So we may accept slightly lower Precision to improve Recall.

In another problem:

> False alarms may be very expensive.

Then we may prefer higher Precision.

That means the “best” threshold is not only a mathematical decision.

It is also a **business decision**.
