label=[]
image_feature = []
image_id=train_labels['id']
for i in image_id:
img=image.load_img(train_dir+i, target_size=(32,32,1), grayscale=False)
img = image.img_to_array(img)
img = img/255
image_feature.append(img)
label.append(train_labels[train_labels['id'] ==i]['has_cactus'].values[0])
X = np.array(image_feature)
y=pd.get_dummies(df['label']).values
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42,
test_size=0.2)
model = Sequential()
model.add(Conv2D(32,kernel_size=(5,5,activation='relu',input_shape=(32,32,3)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(100, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(2, activation='softmax'))
model.compile(loss='categorical_crossentropy',optimizer='Adam',metrics= ['accuracy'])
我使用了以上代码,并使用以下代码来计算混淆矩阵。 从sklearn导入指标 从sklearn.metrics导入confusion_matrix y_pred = model.predict(X_test) 打印(confusion_matrix(y_test,y_pred))
但是我得到了如下的值错误:
分类指标不能同时处理多标签指标和连续多输出指标
我是正确的吗?如果不能,您可以与我分享如何计算此问题的混淆矩阵的代码。谢谢!