Python 如何显示进动、回忆和F1成绩?

Python 如何显示进动、回忆和F1成绩?,python,metrics,precision-recall,Python,Metrics,Precision Recall,我目前正在显示精度、召回率和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) . .

我目前正在显示精度、召回率和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\u测试
y\u pred
。如何获取这些值?

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

当您准备好测试集时,您将这样做以获得
y\u pred

y_pred = model.predict(y_test)

从数据集中可以得到X_测试,y_测试。您应该保留数据集中的一些数据,以便在经过培训的模型上进行测试。所以,在训练结束后,你就可以在你的模型上预测X_测试,得到y_pred。最后,将y_test(真值)与y_pred(模型预测)进行匹配。谢谢,这意味着我必须在开始时删除数据(表示测试数据)。之后,我还使用这些值进行
test\u user\u input、test\u item\u input、test\u labels=get\u train\u samples(test\u mat、num\u negatives)
​​根据您的数据集结构,我调用
model.predic
,我想是这样的。您只需将数据集拆分为两个子集,这两个子集通常称为
train
test
数据。然后我是否需要再次将测试数据输入模型中?:)您将仅在培训期结束后使用它来测量模型的不同分数。例如,您可以检查这个。请注意,我是如何在[15]中拆分块
中的数据集的,然后在[27]
中再次使用块
中的
测试
数据来生成混淆矩阵的。谢谢