0% found this document useful (0 votes)
4 views4 pages

In Machine Learning

A Confusion Matrix is a table used in Machine Learning to evaluate classification models by displaying correct and incorrect predictions. It consists of four components: True Positive (TP), True Negative (TN), False Positive (FP), and False Negative (FN), which help in understanding model performance. The matrix aids in calculating various metrics such as accuracy, precision, recall, and F1-score, providing insights into model errors and effectiveness.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

In Machine Learning

A Confusion Matrix is a table used in Machine Learning to evaluate classification models by displaying correct and incorrect predictions. It consists of four components: True Positive (TP), True Negative (TN), False Positive (FP), and False Negative (FN), which help in understanding model performance. The matrix aids in calculating various metrics such as accuracy, precision, recall, and F1-score, providing insights into model errors and effectiveness.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

In Machine Learning, a Confusion Matrix is a table used to evaluate a classification model.

It shows:

 Correct predictions
 Wrong predictions

Confusion Matrix Structure


For a binary classification problem:

Predicted Yes Predicted No


Actual Yes True Positive (TP) False Negative (FN)
Actual No False Positive (FP) True Negative (TN)

Meaning of Terms
1. True Positive (TP)
Model predicted Yes, and actual answer is also Yes.

Example:

 Student actually got a job


 Model predicted “Yes”

Correct prediction.

2. True Negative (TN)


Model predicted No, and actual answer is also No.

Example:

 Student did not get a job


 Model predicted “No”

Correct prediction.
3. False Positive (FP)
Model predicted Yes, but actual answer is No.

Example:

 Model says student got job


 Actually student did not

Wrong prediction.

4. False Negative (FN)


Model predicted No, but actual answer is Yes.

Example:

 Model says student did not get job


 Actually student got job

Wrong prediction.

Example Confusion Matrix


[[8 2]
[1 9]]

This means:

Predicted No Predicted Yes


Actual No 8 2
Actual Yes 1 9

Interpretation:

 8 → Correctly predicted No
 9 → Correctly predicted Yes
 2 → Wrongly predicted Yes
 1 → Wrongly predicted No

In Python
Using scikit-learn:

from [Link] import confusion_matrix

cm = confusion_matrix(y_test, y_pred)

print(cm)

Visual Understanding
Predicted
No Yes
Actual No TN FP
Actual Yes FN TP

Why Confusion Matrix is Important


It helps understand:

 Where the model is making mistakes


 Whether false positives or false negatives are high
 Real performance beyond simple accuracy

Relation with Metrics


From confusion matrix:

 Accuracy
 Precision
 Recall
 F1-score

are calculated.

import pandas as pd

You might also like