如何在Keras中输出每个班级的准确性

如何在Keras中输出每个班级的准确性

本文介绍了如何在Keras中输出每个班级的准确性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Caffe不仅可以打印整体准确度,而且还可以按类显示准确度.

Caffe can not only print overall accuracy, but also per-class accuracy.

在Keras日志中,只有整体准确性.对我来说,很难计算出单独的班级准确性.

In Keras log, there's only overall accuracy. It's hard for me to calculate the separate class accuracy.

0s-损失:0.0495-acc:0.9818-val_loss:0.0519-val_acc:0.9796

0s - loss: 0.0495 - acc: 0.9818 - val_loss: 0.0519 - val_acc: 0.9796

Epoch 169/200

Epoch 169/200

0s-损失:0.0519-acc:0.9796-val_loss:0.0496-val_acc:0.9815

0s - loss: 0.0519 - acc: 0.9796 - val_loss: 0.0496 - val_acc: 0.9815

Epoch 170/200

Epoch 170/200

0s-损失:0.0496-acc:0.9815-val_loss:0.0514-val_acc:0.9801

0s - loss: 0.0496 - acc: 0.9815 - val_loss: 0.0514 - val_acc: 0.9801

知道如何在keras中输出每个类别的准确性的人吗?

Anybody who knows how to output per-class accuracy in keras?

推荐答案

精度&召回是用于多类分类的更有用的方法(请参见定义).遵循Keras的 MNIST CNN 示例(10类分类),您可以使用classification_report sklearn.metrics :

Precision & recall are more useful measures for multi-class classification (see definitions). Following the Keras MNIST CNN example (10-class classification), you can get the per-class measures using classification_report from sklearn.metrics:

from sklearn.metrics import classification_report
import numpy as np

Y_test = np.argmax(y_test, axis=1) # Convert one-hot to index
y_pred = model.predict_classes(x_test)
print(classification_report(Y_test, y_pred))

这是结果:

         precision    recall  f1-score   support

      0       0.99      1.00      1.00       980
      1       0.99      0.99      0.99      1135
      2       1.00      0.99      0.99      1032
      3       0.99      0.99      0.99      1010
      4       0.98      1.00      0.99       982
      5       0.99      0.99      0.99       892
      6       1.00      0.99      0.99       958
      7       0.97      1.00      0.99      1028
      8       0.99      0.99      0.99       974
      9       0.99      0.98      0.99      1009

avg / total   0.99      0.99      0.99     10000

这篇关于如何在Keras中输出每个班级的准确性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 09:32