Total Pageviews

Monday, August 31, 2026

CONFUSION MATRIX

 

CONFUSION MATRIX







๐Ÿฑ

Confusion Matrix

Is it a CAT or NOT a CAT?

๐Ÿถ
๐Ÿฑ

Click a button above

Learn how the model decides whether something is CAT or NOT A CAT.

๐Ÿฑ๐Ÿถ Confusion Matrix — Cat & Dog

Learn TP, TN, FP and FN by making predictions.

๐Ÿฑ
TRUE POSITIVE

TP

Actual = CAT
Prediction = CAT

Correctly predicted positive.
๐Ÿถ
TRUE NEGATIVE

TN

Actual = DOG
Prediction = NOT A CAT

Correctly predicted negative.
FALSE POSITIVE

FP

Actual = NOT A CAT(DOG)
Prediction = CAT

Dog incorrectly predicted as cat.

FALSE NEGATIVE

FN

Actual = CAT
Prediction = NOT A CAT (DOG)

Cat incorrectly predicted as dog.
๐ŸŽฏ CAT = Positive    |    ๐Ÿถ DOG = Negative

๐Ÿงช Test Cases

Look at the actual animal and choose the model's prediction.

๐Ÿ“Š Confusion Matrix

Predicted CAT Predicted DOG
Actual CAT 0 0
Actual DOG 0 0
Select Test Case 1 to begin.
Total 0
Correct 0
Accuracy 0%

๐Ÿ“Š Confusion Matrix Formula Guide

Learn the important classification formulas, their uses, advantages, disadvantages and interpretation.

Predicted Positive Predicted Negative
Actual Positive TP
True Positive
FN
False Negative
Actual Negative FP
False Positive
TN
True Negative

Accuracy

(TP + TN) / (TP + TN + FP + FN)

Measures the overall percentage of correct predictions.

Precision

TP / (TP + FP)

Measures how many predicted positives are actually positive.

Recall / Sensitivity

TP / (TP + FN)

Measures how many actual positives were correctly detected.

Specificity

TN / (TN + FP)

Measures how many actual negatives were correctly identified.

F1 Score

2 × Precision × Recall / (Precision + Recall)

Balances Precision and Recall.

Fฮฒ Score

(1 + ฮฒ²)PR / (ฮฒ²P + R)

Allows different importance to Precision and Recall.

False Positive Rate

FP / (FP + TN)

Measures the percentage of negatives incorrectly classified as positive.

False Negative Rate

FN / (FN + TP)

Measures the percentage of positives incorrectly classified as negative.

Negative Predictive Value

TN / (TN + FN)

Measures how reliable a negative prediction is.

Positive Predictive Value

TP / (TP + FP)

Another name for Precision.

Balanced Accuracy

(Sensitivity + Specificity) / 2

Useful when classes are imbalanced.

MCC

(TP×TN − FP×FN) / √[(TP+FP)(TP+FN)(TN+FP)(TN+FN)]

Measures the quality of binary classification.

Threat Score / CSI

TP / (TP + FN + FP)

Useful when the positive class is more important.

Diagnostic Odds Ratio

(TP × TN) / (FP × FN)

Compares the odds of a positive result in positives versus negatives.

Error Rate

(FP + FN) / Total

Measures the overall percentage of incorrect predictions.

1️⃣ Accuracy

Accuracy = (TP + TN) / (TP + TN + FP + FN)

๐Ÿ“Œ Use

Used to measure the overall correctness of a classification model. It is particularly useful when the classes are reasonably balanced.

✅ Advantages

• Very easy to understand.
• Considers both positive and negative predictions.
• Useful for balanced datasets.

❌ Disadvantages

• Can be misleading with imbalanced datasets.
• Does not tell us whether errors are FP or FN.
• A high accuracy does not always mean a good model.

๐Ÿ’ก Interpretation

If Accuracy = 95%, approximately 95% of all predictions are correct.

2️⃣ Precision

Precision = TP / (TP + FP)

๐Ÿ“Œ Use

Use Precision when False Positives are costly. For example, when a system should avoid incorrectly labeling something as positive.

✅ Advantages

• Focuses on the quality of positive predictions.
• Useful when False Positives are expensive.
• Important in spam detection and recommendation systems.

❌ Disadvantages

• Ignores True Negatives.
• High Precision can be achieved by predicting positive very rarely.
• Does not measure all actual positive cases.

๐Ÿ’ก Interpretation

Precision = 90% means 90% of the observations predicted as positive were actually positive.

3️⃣ Recall / Sensitivity

Recall = TP / (TP + FN)

๐Ÿ“Œ Use

Use Recall when False Negatives are dangerous. Examples include disease detection, fraud detection and security systems.

✅ Advantages

• Measures the ability to detect actual positives.
• Very useful when missing a positive case is costly.
• Important in medical screening.

❌ Disadvantages

• Does not consider True Negatives.
• Increasing Recall can increase False Positives.
• High Recall alone does not guarantee a good model.

๐Ÿ’ก Interpretation

Recall = 95% means the model detected 95% of all actual positive cases.

4️⃣ Specificity

Specificity = TN / (TN + FP)

๐Ÿ“Œ Use

Used to measure how well the model identifies negative cases. It is important when False Positives must be minimized.

✅ Advantages

• Measures correct identification of negative cases.
• Useful in medical testing and screening.
• Helps control False Positives.

❌ Disadvantages

• Does not measure how well positive cases are detected.
• High Specificity may occur with poor Recall.

5️⃣ F1 Score

F1 = 2 × Precision × Recall / (Precision + Recall)

๐Ÿ“Œ Use

Used when both Precision and Recall are important, especially for imbalanced datasets.

✅ Advantages

• Combines Precision and Recall into one value.
• Useful for imbalanced datasets.
• Penalizes models with poor Precision or Recall.

❌ Disadvantages

• Ignores True Negatives.
• May hide whether Precision or Recall is the actual problem.
• Not always suitable when TN is important.

6️⃣ Fฮฒ Score

Fฮฒ = (1 + ฮฒ²)PR / (ฮฒ²P + R)

๐Ÿ“Œ Use

Used when Precision and Recall do not have equal importance. ฮฒ > 1 gives more importance to Recall, while ฮฒ < 1 gives more importance to Precision.

✅ Advantages

• Flexible metric.
• Allows domain-specific priorities.
• Useful when one type of error is more costly.

❌ Disadvantages

• More difficult to understand than F1.
• Requires choosing an appropriate ฮฒ value.

7️⃣ False Positive Rate

FPR = FP / (FP + TN)

๐Ÿ“Œ Use

Used to measure how often negative observations are incorrectly classified as positive.

✅ Advantage

• Very useful for understanding False Positive errors.
• Important for ROC curve analysis.

❌ Disadvantage

• Does not measure False Negatives.
• Alone it cannot describe overall model performance.

8️⃣ False Negative Rate

FNR = FN / (FN + TP)

๐Ÿ“Œ Use

Used to determine how many actual positive cases were missed.

✅ Advantages

• Directly measures missed positive cases.
• Important when False Negatives are dangerous.

❌ Disadvantages

• Ignores True Negatives.
• Does not show False Positive behavior.

9️⃣ Negative Predictive Value

NPV = TN / (TN + FN)

๐Ÿ“Œ Use

Used to determine how trustworthy a negative prediction is.

✅ Advantages

• Useful when negative predictions are important.
• Particularly useful in diagnostic applications.

❌ Disadvantages

• Strongly affected by class prevalence.
• Not sufficient as a standalone metric.

๐Ÿ”Ÿ Balanced Accuracy

Balanced Accuracy = (Sensitivity + Specificity) / 2

๐Ÿ“Œ Use

Especially useful when the dataset contains unequal numbers of positive and negative observations.

✅ Advantages

• Better than ordinary Accuracy for imbalanced datasets.
• Gives equal importance to both classes.

❌ Disadvantages

• Does not directly indicate Precision.
• Can still hide some types of prediction errors.

1️⃣1️⃣ Matthews Correlation Coefficient

MCC = (TP×TN − FP×FN) / √[(TP+FP)(TP+FN)(TN+FP)(TN+FN)]

๐Ÿ“Œ Use

MCC is particularly useful for evaluating binary classifiers when the classes are highly imbalanced.

✅ Advantages

• Considers all four confusion-matrix components.
• Works well with imbalanced datasets.
• Values range from −1 to +1.

❌ Disadvantages

• Formula is more complicated.
• More difficult for beginners to interpret.

1️⃣2️⃣ Threat Score / Critical Success Index

CSI = TP / (TP + FN + FP)

๐Ÿ“Œ Use

Useful when the positive class is the main focus and both False Positives and False Negatives are important.

✅ Advantages

• Focuses on the positive class.
• Penalizes both FP and FN.

❌ Disadvantages

• Ignores True Negatives.
• Not ideal when negative-class performance is equally important.

1️⃣3️⃣ Error Rate

Error Rate = (FP + FN) / Total

๐Ÿ“Œ Use

Used to calculate the overall proportion of incorrect predictions.

✅ Advantages

• Simple to calculate.
• Directly shows the proportion of wrong predictions.

❌ Disadvantages

• Does not distinguish between FP and FN.
• Can be misleading with imbalanced datasets.

No comments:

Post a Comment