Measuring logistic model performance

As you know by now, several metrics exist for measuring the performance of a logistic regression model. In this last exercise, you'll manually calculate accuracy, sensitivity, and specificity. Recall the following definitions:

Accuracy is the proportion of predictions that are correct. $$ \text{accuracy} = \frac{TN + TP}{TN + FN + FP + TP} $$

Sensitivity is the proportion of true observations that are correctly predicted by the model as being true. $$ \text{sensitivity} = \frac{TP}{TP + FN} $$

Specificity is the proportion of false observations that are correctly predicted by the model as being false. $$ \text{specificity} = \frac{TN}{TN + FP} $$

churn, mdl_churn_vs_relationship, and conf_matrix are available.

This exercise is part of the course

Introduction to Regression with statsmodels in Python

View Course

Exercise instructions

  • Extract the number of true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN) from conf_matrix.
  • Calculate the accuracy of the model.
  • Calculate the sensitivity of the model.
  • Calculate the specificity of the model.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Extract TN, TP, FN and FP from conf_matrix
TN = ____
TP = ____
FN = ____
FP = ____

# Calculate and print the accuracy
accuracy = ____
print("accuracy: ", accuracy)

# Calculate and print the sensitivity
sensitivity = ____
print("sensitivity: ", sensitivity)

# Calculate and print the specificity
specificity = ____
print("specificity: ", specificity)