分类混淆矩阵错误消息

时间:2020-02-29 01:15:35

标签: python pandas keras

我正在尝试根据分类创建混淆矩阵。 Y_pred_one_hot.shape和Y_true_one_hot.shape返回(11,13),y_pred和y_true返回13个整数的列表。但是,我收到了计算cm_df的错误消息:“传递的值的形状为(10,10),索引表示为(13,13)”。

model.load_weights('best_model.h5')

# Test
Y_pred_one_hot = model.predict_generator(generator=test_set, verbose=1)
y_pred = np.argmax(Y_pred_one_hot, axis=1)

print(Y_pred_one_hot.shape)
print(y_pred)

# Get GT labels
Y_true_one_hot = np.squeeze(np.array([test_set.__getitem__(i)[1] for i in range(len(test_set))]))
y_true = np.argmax(Y_true_one_hot, axis=1)

print(Y_true_one_hot.shape)
print(y_true)

# Assessment
conf_mat = confusion_matrix(y_true, y_pred)
print("Confusion Matrix")
print(conf_mat)

class_names = ["Barge", "Bulk Carrier", "Cargo Ship", "Ferry/Passenger V.", "Fishing V.", "Motorboat", "Support/Naval Small Craft", "Naval Warship", "Sailing V.", "Tanker", "Tugboat", "Yacht", "None"]
cm_df = pd.DataFrame(conf_mat, index=class_names, columns=class_names)

这是我收到的错误消息。

enter image description here

0 个答案:

没有答案