Menu

Confusion Matrix

Confusion Matrix

A Confusion Matrix summarizes the model's predictions by comparing the predicted labels with the actual labels.

It consists of four values:

  • True Positive (TP): Fake reviews correctly classified as fake.
  • True Negative (TN): Genuine reviews correctly classified as genuine.
  • False Positive (FP): Genuine reviews incorrectly classified as fake.
  • False Negative (FN): Fake reviews incorrectly classified as genuine.

The Confusion Matrix helps identify the types of errors made by the model.

Generate the Confusion Matrix

from sklearn.metrics import confusion_matrix

cm = confusion_matrix(y_test, y_pred)

cm

Visualize the Confusion Matrix

plt.figure(figsize=(6,5))

sns.heatmap(

cm,

annot=True,

fmt='d',

cmap='Blues',

xticklabels=['Genuine', 'Fake'],

yticklabels=['Genuine', 'Fake']

)

plt.xlabel("Predicted Label")

plt.ylabel("Actual Label")

plt.title("Confusion Matrix")

plt.show()

Explanation

The diagonal values represent correctly classified reviews, while the off-diagonal values indicate misclassified reviews.

A model with higher diagonal values generally performs better.