0% found this document useful (0 votes)
39 views5 pages

Confusion Matrix & Box Plot

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views5 pages

Confusion Matrix & Box Plot

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Confusion matrix:

A confusion matrix is a table that shows how well a machine learning algorithm is performing a
classification task.

• True positive (TP): A positive prediction that was correct

• True negative (TN): A negative prediction that was correct

• False positive (FP): A positive prediction that was incorrect

• False negative (FN): A negative prediction that was incorrect


Given data:

0 – Negative, 1 – Positive

Actual_data : [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]

Predicted_data : [1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1]

True Negatives (TN) = 4 (0-0)

False Positives (FP) = 3 (0-1)

False Negatives (FN) = 3 (1-0)

True Positives (TP) = 5 (1-1)

Accuracy:
Accuracy in a confusion matrix is the proportion of correct classifications out of all classifications, and is
calculated by dividing the total number of correct classifications by the total number of classifications.

Accuracy = (TP+TN)/(TP+TN+FP+FN) = 9/15 = 0.6 (60.00%)

Precision:
In a confusion matrix, precision is a metric that measures the quality of a model's positive predictions.
Precision measures the proportion of true positive predictions among all positive predictions.

Precision = TP/(TP+FP) = 5/8 = 0.625 (62.50%)

Recall:
In a confusion matrix, recall is a metric that measures how well a model identifies true positives. Recall
is the total number of the actual positive cases that were predicted correctly.

Recall = TP/(TP+FN) = 5/8 = 0.625 (62.50%)

F1 Score:
The F1 score is a metric used to evaluate a classifier's performance in a confusion matrix by combining
the precision and recall scores into a single value. To calculate the F1 score, we can use a confusion
matrix, which summarizes the predictive performance of a model on a binary classification task (positive
and negative classes).

F1 Score = (2*Precision*Recall)/(Precision+Recall) = (2*0.625*0.625)/(0.625+0.625)

= 0.78125/1.25 = 0.625 (62.50%)


Box Plot:
To create a box plot and identify outliers manually, let’s go through each step of the process using the
provided data.

Step 1: Arrange Data in Ascending Order

First, we need to sort the data in ascending order:

Data (sorted): −5,2,4,6,8,10,12,14,16,18,20,24,26,50,70

Step 2: Find the Quartiles (Q1, Q2, Q3)

1. Median (Q2): The median divides the data into two halves.

o There are 15 data points, so the median is the 8th value.

o Q2 = 14

2. First Quartile (Q1): This is the median of the lower half (first 7 values).

o Lower half: −5,2,4,6,8,10,12

o Median of this subset (4th value): Q1=6

3. Third Quartile (Q3): This is the median of the upper half (last 7 values).

o Upper half: 16,18,20,24,26,50,70

o Median of this subset (4th value): Q3= 24

Step 3: Calculate the Interquartile Range (IQR)

IQR=Q3−Q1 =24−6=18

Step 4: Determine the Outlier Boundaries

To identify outliers, we use the following formulas:

• Lower Bound: Q1−1.5×IQR

• Upper Bound: Q3+1.5×IQR

Lower Bound: = 6−1.5×18 =6−27 =−21

Upper Bound: = 24+1.5×18 =24+27 =51

Step 5: Identify Outliers


Any value outside the range [−21,51] is an outlier.

• In this case, the only outlier is 70 (as it is greater than 51).

Summary of Results

Q1: 6

Q2 (Median): 14

Q3: 24

IQR: 18

Outliers: 70

Lower Bound: -21

Upper Bound: 51

Box Plot Visualization

To create the box plot for this data, I’ll now use Python to visualize it.
Here is the box plot for the given data, with the outlier (70) clearly shown beyond the whiskers. This
value exceeds the upper boundary of 51, confirming it as an outlier.

You might also like