【问题标题】:How to Calculating ROC and AUC in Caffe?Caffe中如何计算ROC和AUC?
【发布时间】:2017-11-12 05:39:32
【问题描述】:

我已经在 Caffe 中训练了一个二元类 CNN,现在我想绘制 ROC 曲线并计算 AUC 值。我有两个问题: 1)如何用python绘制Caffe中的ROC曲线? 2) 如何计算ROC曲线的AUC值?

【问题讨论】:

    标签: python machine-learning neural-network caffe roc


    【解决方案1】:

    Python 在sklearn.metrics 模块中有roc_curveroc_auc_score 函数,只需导入并使用它们。

    假设您有一个二进制预测层,它输出二进制类概率的两个向量(我们称之为"prob"),那么您的代码应该如下所示:

    import caffe
    from sklearn import metrics
    # load the net with trained weights
    net = caffe.Net('/path/to/deploy.prototxt', '/path/to/weights.caffemodel', caffe.TEST)
    y_score = []  
    y_true = []
    for i in xrange(N): # assuming you have N validation samples
        x_i = ... # get i-th validation sample
        y_true.append( y_i )  # y_i is 0 or 1 the TRUE label of x_i
        out = net.forward( data=x_i )  # get prediction for x_i
        y_score.append( out['prob'][1] ) # get score for "1" class
    # once you have N y_score and y_true values
    fpr, tpr, thresholds = metrics.roc_curve(y_true, y_score, pos_label=1)
    auc = metrics.roc_auc_score(y_true, y_scores)
    

    【讨论】:

    • 我已经用和你一样的方法解决了,不过还是谢谢你的回答!
    猜你喜欢
    • 2016-01-23
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 2021-06-12
    • 2015-11-24
    • 2021-09-06
    • 2015-08-02
    相关资源
    最近更新 更多