title: Binary classification - computing average of accuracy per class does not equal overall accuracy
body: <p>I have a binary classification problem with balanced number of examples per class. When testing the performance of the classifier on the test set, if I use all examples from both classes I get an accuracy of 79.87 %. However, when testing on the classes individually, accuracy per class 1 is 73.41 % and accuracy per class 2 is 63.31 %. The problem is that if I compute the average accuracy for the two classes, i.e. (73.41 + 63.31) /2 = 68.36 %, which does not equal 79.87 %.</p>
  
  <p>How is this possible? I am using the model.evaluate function from Keras in order to obtain the accuracy numbers. My code is as follows: </p>
  
  <pre><code> model.compile(loss='binary_crossentropy',
              optimizer=optim,
              metrics=['accuracy'])
  
  earlystop = EarlyStopping(monitor='val_acc', min_delta=0.001, patience=5, verbose=0, mode='auto')
  callbacks_list = [earlystop]
  
  X_train, y_train, X_val, y_val = data()
  hist = model.fit(X_train, y_train, validation_data=(X_val, y_val), epochs=30, batch_size=batch_size, shuffle=True, callbacks=callbacks_list)
  #get training accuracy
  training_accuracy = np.mean(hist.history["acc"])
  validation_accuracy = np.mean(hist.history["val_acc"])
  print("Training accuracy: %.2f%%" % (training_accuracy * 100))
  print("Validation accuracy: %.2f%%" % (validation_accuracy * 100))
  
  scores = model.evaluate(X_test, y_test, verbose=2)
  y_pred = model.predict_classes(X_test)
  print(metrics.classification_report(y_test, y_pred))
  print("Testing loss: %.2f%%" % (scores[0]))
  print("Testing accuracy: %.2f%%" % (scores[1]*100))
  </code></pre>
  
  <p>Why do I get results which don't add up? My setup is very trivial so I am sure there is no bug in my code. Thank you!</p>