Search⌘ K
AI Features

Exercise: Calculating True and False Rates and Confusion Matrix

Explore how to calculate true positive, false negative, true negative, and false positive rates manually and using scikit-learn in Python. Understand how these metrics form the confusion matrix and what they reveal about a model's performance in binary classification. You will learn to evaluate a logistic regression model and interpret key model evaluation metrics like sensitivity and specificity.

Confusion matrix calculation in Python

In this exercise, we’ll use the test data and model predictions from the logistic regression model we created previously, using only the EDUCATION feature. We will illustrate how to manually calculate the true and false positive and negative rates, as well as the numbers of true and false positives and negatives needed for the confusion matrix. Then we will show a quick way to calculate a confusion matrix with scikit-learn. Perform the following steps to complete the exercise, noting that some code from the previous lesson must be run before doing this exercise:

  1. Run this code to calculate the number of positive samples:

...