【问题标题】:Confusion matrix and test accuracy for PyTorch CNN tutorialPyTorch CNN 教程的混淆矩阵和测试精度
【发布时间】:2020-04-07 08:28:22
【问题描述】:

我有兴趣只报告训练和测试的准确性以及混淆矩阵(比如使用 sklearn 混淆矩阵)。我怎样才能做到这一点?当前教程仅报告训练/验证准确性,我很难弄清楚如何在其中合并 sklearn 混淆矩阵代码。原教程链接:https://github.com/bentrevett/pytorch-sentiment-analysis/blob/master/4%20-%20Convolutional%20Sentiment%20Analysis.ipynb

【问题讨论】:

  • 展示你的努力和代码,然后询问错误或错误在哪里?

标签: python sentiment-analysis confusion-matrix conv-neural-network


【解决方案1】:

与教程中定义的binary_accuracy 函数非常相似,您可以实现任何您想要的指标。您只需要一组模型预测(在本例中为preds)和真实目标(y)。

例如,对于混淆矩阵,您可以执行以下操作:

from sklearn.metrics import confusion_matrix

def compute_confusion_matrix(preds, y):
    #round predictions to the closest integer
    rounded_preds = torch.round(torch.sigmoid(preds))
    return confusion_matrix(y, rounded_preds)

【讨论】:

    猜你喜欢
    • 2020-02-23
    • 2021-12-08
    • 2022-01-04
    • 2019-06-13
    • 2012-11-12
    • 1970-01-01
    • 2020-03-09
    • 2018-11-22
    • 2017-04-05
    相关资源
    最近更新 更多