我正在使用以下Keras代码对mnist数据进行分类。从confusion_matrix命令sklearn.metrics我得到了混淆矩阵,从TruePositive= sum(numpy.diag(cm1))命令我得到了真正。但是我混淆了如何获得真否定,假肯定,假否定。我从这里阅读解决方案,但用户评论使我感到困惑。请帮助编写代码以获取参数。
from sklearn.metrics import confusion_matrix
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
import numpy as np
(x_train, y_train), (x_test, y_test) = mnist.load_data()
batch_size = 128
num_classes = 10
epochs = 1
img_rows, img_cols = 28, 28
y_test1=y_test
if K.image_data_format() == 'channels_first':
x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)
x_test = x_test.reshape(x_test.shape[0], 1, …Run Code Online (Sandbox Code Playgroud) 您如何计算多类别分类问题的正确率和错误率?说,
y_true = [1, -1, 0, 0, 1, -1, 1, 0, -1, 0, 1, -1, 1, 0, 0, -1, 0]
y_prediction = [-1, -1, 1, 0, 0, 0, 0, -1, 1, -1, 1, 1, 0, 0, 1, 1, -1]
Run Code Online (Sandbox Code Playgroud)
混淆矩阵由来计算metrics.confusion_matrix(y_true, y_prediction),但这只是解决了问题。
@seralouk的答案后编辑。在此,该类别-1应被视为否定词,而0和1是正值的变体。
python confusion-matrix scikit-learn multiclass-classification