Drawing a mosaic plot of the confusion matrix

While calculating the performance matrix might be fun, it would become tedious if you needed multiple confusion matrices of different models. Luckily, the .pred_table() method can calculate the confusion matrix for you.

Additionally, you can use the output from the .pred_table() method to visualize the confusion matrix, using the mosaic() function.

churn and mdl_churn_vs_relationship are available.

This exercise is part of the course

Introduction to Regression with statsmodels in Python

View Course

Exercise instructions

  • Import the mosaic() function from statsmodels.graphics.mosaicplot.
  • Create conf_matrix using the .pred_table() method and print it.
  • Draw a mosaic plot of the confusion matrix.

Hands-on interactive exercise

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

# Import mosaic from statsmodels.graphics.mosaicplot
____

# Calculate the confusion matrix conf_matrix
conf_matrix = ____

# Print it
print(conf_matrix)

# Draw a mosaic plot of conf_matrix
____
plt.show()