Confusion Matrix: For Evaluating The KNN Model
Confusion Matrix: For Evaluating The KNN Model
• useful tool for calibrating the output of a model.....a tool for evaluating the
performance of the model
• examines all possible outcomes...True Positive (TP), True Negative(TN), False
Positive(FP), False Negative(FN)
• categorises the predictions against the actual values....it is a 2-dim matrix of predicted
values X actual values
• gives lot of additional data in addition to the accuracy of the KNN model.
• has this name as it shows how confused the model is between predicted outcome
values and actual outcome values.
• The columns in CM represent actual classes and rows represent the predicted
classes….or VV
How does Confusion Matrix (CM) look like?
What does TP, TN, FP, FN stand for in the Confusion Matrix (CM)?
TP: these are cases where the model correctly predicts outcome Y
FP: these are cases where the model incorrectly predicts outcome Y
TN: these are cases where the model correctly predicts N
FN: these are cases where the model incorrectly predicts outcome N
Confusion Matrix
Type 2
We can measure other additional information in Confusion Matrix
Actual values
Predicted values
For prediction of prostrate cancer among men
based on their medical report for test 1 and test 2.
• In the given example (prostrate cancer), it can be seen that there are high
incidences of false positives (45 out of 45+55=100). Therefore, precision
given by TP/TP+FP ……is just 45%. This means that we are falsely
predicting prostrate cancer 55% of the time. Our model is thus NOT
precise.
Command in R to execute the Confusion Matrix
confusionMatrix(data = m1,factor(fibre_test_target))
1. We specify the predicted data and the actual data as the arguments
2. Both the datasets should be of factor type….convert them to factor in case it is not
print (conf_matrix)
Model’s accuracy is 1