繁体   English   中英

如何显示进动、召回和 F1 分数?

[英]How to show Precession, Recall and F1-Score?

我目前正在显示精度、召回率和 fscore。 现在我的问题是我该怎么做? 我尝试的是以下内容:

num_users, num_items = train_mat.shape
user_input, item_input, labels = get_train_samples(train_mat, num_negatives)
val_user_input, val_item_input, val_labels = get_train_samples(val_mat, num_negatives)
.
.
.
history = model.fit([np.array(user_input), np.array(item_input)], np.array(labels), 
                 epochs=EPOCHS, verbose=VERBOSE, shuffle=True, batch_size = BATCH_SIZE,
                 validation_data=([np.array(val_user_input), np.array(val_item_input)], np.array(val_labels)),
                  callbacks=CALLBACKS)
.
.
.
# Precision, recall and fscore
from sklearn.metrics import precision_recall_fscore_support, confusion_matrix, roc_curve, auc
precision, recall, fscore, _ = precision_recall_fscore_support(y_test, y_pred, average='weighted')

print('Precision, recall, and F1 score, averaged and weighted by number of instances in each class:')
print('precision: {}'.format(precision))
print('recall: {}'.format(recall))
print('f1 score: {}\n'.format(fscore))

precision, recall, fscore, _ = precision_recall_fscore_support(y_test, y_pred)

print('Precision, recall, and F1 score, per class [0 1]:')
print('precision: {}'.format(precision))
print('recall: {}'.format(recall))
print('f1 score: {}'.format(fscore))


cm = confusion_matrix(y_test, y_pred)
sns.heatmap(cm, annot=True)

不幸的是,我不知道如何获得y_testy_pred 我如何获得这些值?

你应该有y_test作为测试集来测试你的模型,如果你没有这样的集,你可以使用 sklearn train test split 来获取训练集和测试集。 这是如何使用它的链接: sklearn train test split

当您拥有测试集时,您将这样做以获得y_pred

y_pred = model.predict(y_test)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM