简体   繁体   English

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

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

I am currently in the process of displaying precision, recall and fscore.我目前正在显示精度、召回率和 fscore。 Now my question is how do I do this?现在我的问题是我该怎么做? What I tried is the following:我尝试的是以下内容:

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)

Unfortunately I don't know how to get y_test and y_pred .不幸的是,我不知道如何获得y_testy_pred How do I get these values?我如何获得这些值?

you shall have y_test as the test set to test your model and if you dont have such a set you can use sklearn train test split for getting a training set and a test set.你应该有y_test作为测试集来测试你的模型,如果你没有这样的集,你可以使用 sklearn train test split 来获取训练集和测试集。 Here is the link for how to use it: sklearn traiin test split这是如何使用它的链接: sklearn train test split

and when you will have your test set you will do this to get y_pred :当您拥有测试集时,您将这样做以获得y_pred

y_pred = model.predict(y_test)

暂无
暂无

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

相关问题 如何从Sklearn分类报告中返回精确度,召回率和F1分数的平均分数? - How to return average score for precision, recall and F1-score from Sklearn Classification report? 如何使用交叉验证在多类数据集中对精度、召回率和 f1-score 进行评分? - how to score precision, recall and f1-score in a multi-class dataset using cross-validate? 如何计算神经网络模型中的准确率、召回率和 F1 分数? - How can I calculate precision, recall and F1-score in Neural Network models? 如何在 python 中计算一类 SVM 的准确度、F1 分数、召回率、精度和 EER? - How to compute accuracy, F1-score, recall, precision and EER for one-class SVM in python? 如何使用 scikit learn 计算多类案例的准确率、召回率、准确率和 f1 分数? - How to compute precision, recall, accuracy and f1-score for the multiclass case with scikit learn? 完美的精度,召回率和f1得分,但预测不佳 - Perfect precision, recall and f1-score, yet bad prediction 如何提高 CNN 分类中的 F1-score - How to improve the F1-score in CNN classification 微观宏观和加权平均值都具有相同的精度,召回率,f1分数 - micro macro and weighted average all have the same precision, recall, f1-score 打印包含每个查询的准确率、精确度、召回率和 F1 分数的字典 - Print dictionary containing accuracy, precision, recall and F1-score for each query 为什么F1-score,Recall,Precision都等于1? (图像分类linearSVM) - Why F1-score, Recall, Precision all equal to 1? (image classification linearSVM)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM