Menu

Creating the Confusion Matrix

Creating the Confusion Matrix

A confusion matrix summarizes the model’s predictions.

Code

from sklearn.metrics import confusion_matrix

cm = confusion_matrix(

Y_test,

testing_predictions

)

sns.heatmap(

cm,

annot=True,

fmt='d',

cmap='Blues'

)

plt.title("Confusion Matrix")

plt.xlabel("Predicted")

plt.ylabel("Actual")

plt.show()

Explanation

The confusion matrix displays:

  • Correctly classified genuine transactions
  • Correctly classified fraudulent transactions
  • False positives
  • False negatives

It provides a detailed understanding of the model’s strengths and weaknesses.