Confusion Matrix Display in Jupyter

  • Make sure scikit-learn and matplotlib are both installed:

pip install scikit-learn matplotlib

  • Import ConfusionMatrixDisplay and pyplot
from sklearn.metrics import ConfusionMatrixDisplay
import matplotlib.pyplot as plt
 
ConfusionMatrixDisplay.from_predictions(y_test, y_pred, cmap="Blues")
plt.xticks(rotation=45)  # Rotate x-axis labels to 45 degrees
plt.show()  # Display the plot