簡體   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