代码之家  ›  专栏  ›  技术社区  ›  Simplicity

如何根据这些数据绘制ROC曲线?

  •  0
  • Simplicity  · 技术社区  · 7 年前

    我已经使用Keras训练了一个卷积神经网络(CNN),并做了以下工作,以便找到测试数据集的准确性:

    for root, dirs, files in os.walk(test_directory):
        for file in files:
            img = cv2.imread(root + '/' + file)
            img = cv2.resize(img,(512,512),interpolation=cv2.INTER_AREA)
            img = np.expand_dims(img, axis=0)
            img = img/255.0
            if os.path.basename(root) == 'nevus':
                label = 1
            elif os.path.basename(root) == 'melanoma':
                label = 0
            img_class = model.predict_classes(img)
            prediction = img_class[0]
            if prediction == label:
                correct_classification = correct_classification + 1
            print 'This is the prediction: '
            print prediction
            number_of_test_images = number_of_test_images + 1
    
    print 'correct results:'
    print correct_classification
    
    print 'number of test images'
    print number_of_test_images
    
    print 'Accuray:'
    print number_of_test_images/correct_classification * 100
    

    在测试数据集上测试模型,有没有办法找到ROC曲线?

    谢谢。

    1 回复  |  直到 7 年前
        1
  •  2
  •   HakunaMaData    7 年前

    [Prob Threshold, TP, FP] 把它画出来。你需要使用 model.predict_proba(...)

    对于多类课程来说,这有点棘手。不过你有一些选择。您可以为每个类(一对多的情况)绘制一条ROC曲线,基本上将主要类与所有其他类进行二值化。或者,对于多类你可以做什么sklean attempts

    推荐文章