11.2 Confusion Matrix

A confusion Matrix is the 2x2 table that compares the predicted classes to the true classes.

This table was generated by drawing a random Bernoulli variable with probability \(p_{i}\). This assumes that probabilities can range from [0,1], but if you look at the plots above, the predicted probabilities max out around 0.5.

Often we adjust the cutoff value to improve accuracy. This is where we have to put our gut feeling of what probability constitutes “high risk”. For some models, this could be as low as 30%. It’s whatever the probability is that optimally separates the classes. This is an important tuning parameter because since the models we build are only based on data we measured, often there are other unmeasured confounding factors that affect the predicted probability. So our predictions don’t span the full range from [0,1].

Using the above plots, where should we put the cutoff value? At what probability should we classify a record as “depressed”?

There are many different types of criteria that can be used to find the optimal cutoff value. But first we need to understand the expanded borders of a [Confusion Matrix].

Confusion matrix. Credit: Wikipedia

Confusion matrix. Credit: Wikipedia

Using the confusionMatrix function inside the caret package performs all these calculations for us.

You must specify what the ‘event’ is. This is also another place where the factor ordering of binary variables can cause headache. Another reason to control your factors!
  • 195 people were correctly predicted to not be depressed (True Negative)
  • 49 people were incorrectly predicted to be depressed (False Positive)
  • 10 people were incorrectly predicted to not be depressed (False Negative)
  • 15 people were correctly predicted to be depressed (True Positive)