def evaluate_classification(predictions, labels, output_file, configuration): cm = confusion_matrix(labels, [0 if p < 0.5 else 1 for p in predictions]) recall = cm[1][1] / (cm[1][1] + cm[1][0]) precision = cm[1][1] / (cm[1][1] + cm[0][1]) accuracy = (cm[0][0] + cm[1][1]) / (cm[0][0] + cm[0][1] + cm[1][0] + cm[1][1]) save_confusion_matrix(cm, output_file[:-7] + '.png') # format output for LaTeX output_file.write('%d & %d & %d & %s & %f & %f & %f \\\\ \n' % (configuration['epochs'], configuration['layers'], configuration['units'], configuration['class'], accuracy, precision, recall))
def evaluate_classification(predictions, labels, output_file_name, output_file, configuration): print labels[:10], [0 if p < 0.5 else 1 for p in predictions[:10]] cm = confusion_matrix(labels, [0 if p < 0.5 else 1 for p in predictions]) print cm, cm[0][0], cm[0][1], cm[1][0], cm[1][1], float(cm[0][0] + cm[0][1] + cm[1][0] + cm[1][1]) recall = float(cm[1][1]) / float(cm[1][1] + cm[1][0]) \ if cm[1][1] + cm[1][0] > 0 else 0 precision = float(cm[1][1]) / float(cm[1][1] + cm[0][1]) \ if cm[1][1] + cm[0][1] > 0 else 0 accuracy = float(cm[0][0] + cm[1][1]) / float(cm[0][0] + cm[0][1] + cm[1][0] + cm[1][1]) \ if cm[0][0] + cm[0][1] + cm[1][0] + cm[1][1] > 0 else 0 f1 = float(2*precision*recall)/float(precision+recall) if precision + recall > 0 else 0 save_confusion_matrix(cm, output_file_name[:-7] + '.png') # format output for LaTeX output_file.write('%d & %d & %d & %s & %f & %f & %f & %f \\\\ \n' % (configuration['epochs'], configuration['layers'], configuration['units'], configuration['class'], accuracy, precision, recall, f1))