title: Can a Siamese Network model draw ROC Curve?
body: <p>Based on example on Keras
  <a href="https://keras.io/examples/vision/siamese_contrastive/" rel="nofollow noreferrer">https://keras.io/examples/vision/siamese_contrastive/</a></p>
  <p>Here is how I code to get ROC Curve</p>
  <pre><code>from sklearn.metrics import confusion_matrix,accuracy_score, roc_curve, auc
  import seaborn as sns
  sns.set_style(&quot;whitegrid&quot;)
  
  pred = siamese.predict([x_test_1, x_test_2])
  pred = pred[:,0]
  pred_NN_01 = np.where(pred &gt; 0.5, 1, 0) #Turn probability to 0-1 binary output
  #Print accuracy
  acc_NN = accuracy_score(labels_test, pred_NN_01)
  print('Overall accuracy of Neural Network model:', acc_NN)
  
  #Print Area Under Curve
  false_positive_rate, recall, thresholds = roc_curve(labels_test, pred)
  roc_auc = auc(false_positive_rate, recall)
  plt.figure()
  plt.title('Receiver Operating Characteristic (ROC)')
  plt.plot(false_positive_rate, recall, 'b', label = 'AUC = %0.3f' %roc_auc)
  plt.legend(loc='lower right')
  plt.plot([0,1], [0,1], 'r--')
  plt.xlim([0.0,1.0])
  plt.ylim([0.0,1.0])
  plt.ylabel('Recall')
  plt.xlabel('Fall-out (1-Specificity)')
  plt.show()
  
  #Print Confusion Matrix
  cm = confusion_matrix(labels_test, pred_NN_01)
  labels = ['Unchange', 'Change']
  plt.figure(figsize=(8,6))
  sns.heatmap(cm,xticklabels=labels, yticklabels=labels, annot=True, fmt='d', cmap=&quot;Blues&quot;, vmin = 0.2);
  plt.title('Confusion Matrix')
  plt.ylabel('True Class')
  plt.xlabel('Predicted Class')
  plt.show()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Tjpkd.png" rel="nofollow noreferrer">Keras Example ROC Curve</a></p>
  <p><a href="https://i.stack.imgur.com/HxYV4.png" rel="nofollow noreferrer">Keras Example Confusion Matrix</a></p>
  <p>If the code and image is right , since the example is 10 classes (0~9 digit image)
  how if I use other images which only have two classes with this model
  does this ROC Curve code need to change any part?</p>
  <p>Because I've got a strange output with this same code with 2 classes</p>
  <p>the image result kept weird , the confusion matrix doesn't match the ROC curve</p>
  <p><a href="https://i.stack.imgur.com/TOYhU.png" rel="nofollow noreferrer">2 Classes ROC Curve</a></p>
  <p><a href="https://i.stack.imgur.com/31uRT.png" rel="nofollow noreferrer">2 Classes Confusion Matrix</a></p>