zaidmehdi commited on
Commit
2f5f23f
1 Parent(s): f8b3be6

add fct to plot confusion matrix

Browse files
Files changed (1) hide show
  1. src/utils.py +16 -1
src/utils.py CHANGED
@@ -1,4 +1,7 @@
 
 
1
  from sklearn.metrics import accuracy_score, f1_score
 
2
 
3
 
4
  def get_metrics(y_true, y_preds):
@@ -16,4 +19,16 @@ def evaluate_predictions(model:str, train_preds, y_train, test_preds, y_test):
16
  get_metrics(y_train, train_preds)
17
  print("-"*50)
18
  print("Test set:")
19
- get_metrics(y_test, test_preds)
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import seaborn as sns
3
  from sklearn.metrics import accuracy_score, f1_score
4
+ from sklearn.metrics import confusion_matrix
5
 
6
 
7
  def get_metrics(y_true, y_preds):
 
19
  get_metrics(y_train, train_preds)
20
  print("-"*50)
21
  print("Test set:")
22
+ get_metrics(y_test, test_preds)
23
+
24
+
25
+ def plot_confusion_matrix(y_true, y_preds):
26
+ labels = sorted(set(y_true.tolist() + y_preds.tolist()))
27
+ cm = confusion_matrix(y_true, y_preds)
28
+ plt.figure(figsize=(12, 10))
29
+ sns.heatmap(cm, annot=True, cmap="Blues",
30
+ xticklabels=labels, yticklabels=labels)
31
+ plt.xlabel('Predicted Label')
32
+ plt.ylabel('True Label')
33
+ plt.title('Confusion Matrix')
34
+ plt.show()