Sadjad Alikhani commited on
Commit
b837f81
·
verified ·
1 Parent(s): 512ef82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -126,12 +126,24 @@ def plot_confusion_matrix(y_true, y_pred, title):
126
  plt.xlabel('Predicted')
127
  plt.ylabel('Actual')
128
  plt.colorbar()
 
 
129
  plt.xticks([0, 1], labels=[0, 1])
130
  plt.yticks([0, 1], labels=[0, 1])
 
 
 
 
 
 
 
 
 
131
  plt.tight_layout()
132
  plt.savefig(f"{title}.png")
133
  return Image.open(f"{title}.png")
134
 
 
135
  def identical_train_test_split(output_emb, output_raw, labels, percentage_idx):
136
  N = output_emb.shape[0] # Get the total number of samples
137
 
@@ -233,8 +245,8 @@ def process_hdf5_file(uploaded_file, percentage_idx):
233
  print(f'test_data_emb: {test_data_emb.shape}')
234
  pred_raw = classify_based_on_distance(train_data_raw, train_labels, test_data_raw)
235
  pred_emb = classify_based_on_distance(train_data_emb, train_labels, test_data_emb)
236
- print(f'pred_emb: {pred_emb}')
237
- print(f'actual labels: {test_labels}')
238
  # Step 9: Generate confusion matrices for both raw and embeddings
239
  raw_cm_image = plot_confusion_matrix(test_labels, pred_raw, title="Confusion Matrix (Raw Channels)")
240
  emb_cm_image = plot_confusion_matrix(test_labels, pred_emb, title="Confusion Matrix (Embeddings)")
 
126
  plt.xlabel('Predicted')
127
  plt.ylabel('Actual')
128
  plt.colorbar()
129
+
130
+ # Add labels for x and y ticks (Actual/Predicted class labels)
131
  plt.xticks([0, 1], labels=[0, 1])
132
  plt.yticks([0, 1], labels=[0, 1])
133
+
134
+ # Annotate the confusion matrix
135
+ thresh = cm.max() / 2 # Define threshold to choose text color (black or white)
136
+ for i in range(cm.shape[0]):
137
+ for j in range(cm.shape[1]):
138
+ plt.text(j, i, format(cm[i, j], 'd'),
139
+ ha="center", va="center",
140
+ color="white" if cm[i, j] > thresh else "black")
141
+
142
  plt.tight_layout()
143
  plt.savefig(f"{title}.png")
144
  return Image.open(f"{title}.png")
145
 
146
+
147
  def identical_train_test_split(output_emb, output_raw, labels, percentage_idx):
148
  N = output_emb.shape[0] # Get the total number of samples
149
 
 
245
  print(f'test_data_emb: {test_data_emb.shape}')
246
  pred_raw = classify_based_on_distance(train_data_raw, train_labels, test_data_raw)
247
  pred_emb = classify_based_on_distance(train_data_emb, train_labels, test_data_emb)
248
+ #print(f'pred_emb: {pred_emb}')
249
+ #print(f'actual labels: {test_labels}')
250
  # Step 9: Generate confusion matrices for both raw and embeddings
251
  raw_cm_image = plot_confusion_matrix(test_labels, pred_raw, title="Confusion Matrix (Raw Channels)")
252
  emb_cm_image = plot_confusion_matrix(test_labels, pred_emb, title="Confusion Matrix (Embeddings)")