Confusion Matrix in Machine Learning
In this blog, I will try to explain all the basic terminologies of the confusion matrix and how to calculate them, with an example.
We use the confusion matrix to evaluate the performance of a classification model. In this example, we are using a classifier to predict whether it is a dog or a cat. My main aim is to make you understand the intuition behind the terminologies.
TRUE POSITIVE (TP): Prediction is a dog and actually a dog.
TRUE NEGATIVE (TN): Prediction is a cat and actually a cat.
FALSE POSITIVE (FP): Prediction is a dog and actually a cat. Also known as “TYPE I ERROR”.
FALSE NEGATIVE (FN): Prediction is a cat and actually a dog. Also known as “TYPE II ERROR”.
TRUE POSITIVE RATE (TPR) / RECALL / SENSITIVITY / HIT RATE
When it is actually a dog, how many times our classifier predicts it as a dog. Rate of correctly predicting dogs.
TRUE NEGATIVE RATE (TNR) / SPECIFICITY / SELECTIVITY
When it is actually a cat, how many times our classifier predicts it as a cat. Rate of correctly predicting cats.
FALSE POSITIVE RATE (FPR) / FALL-OUT
When it is actually a cat, how many times our classifier predicts it as a dog.
FALSE NEGATIVE RATE (FNR) / MISS RATE
When it is actually a dog, how many times our classifier predicts it as a cat.
POSITIVE PREDICTIVE VALUE (PPV) / PRECISION
When our classifier predict dog, how many times it is correct?
NEGATIVE PREDICTIVE VALUE (NPV)
When our classifier predict cat, how many times it is correct?
ACCURACY
How often our classifier predicts correctly?
MISCLASSIFICATION RATE / ERROR RATE
How often our classifier predicts incorrectly?
F1-SCORE
We cannot compare precision and recall together so to make it comparable we take the weighted average of precision and recall.
F1-Score is the harmonic mean of precision and recall and is crucial when the false negative and false positive are important in our classifier, it also shows a better measure in case of imbalance classes.
PREVALENCE
How often does the dog actually occur in our sample?
I hope you got some basic idea of what exactly is confusion matrix. If this post helped you please consider giving an👏🏼to motivate me.