【问题标题】:How to acquire sensitivity and specificty(true positive rate and true negative rate) from sklearn's gridsearchcv?如何从 sklearn gridsearchcv 获取敏感性和特异性(真阳性率和真阴性率)?
【发布时间】:2016-07-14 22:09:10
【问题描述】:

我一直在使用带有 RBF SVM(二元分类器)的 Gridsearchcv 来获得验证准确度热图。我使用的代码几乎直接来自 SKlearn 的网站。有没有办法从中找到敏感性和特异性?至于Gridsearchcv使用的参数值的范围?

【问题讨论】:

    标签: python machine-learning scikit-learn svm grid-search


    【解决方案1】:

    如果您的问题是二分类或多分类,那么 confusion matrix 可能就是您要找的。​​p>

    from sklearn.metrics import confusion_matrix
    
    y_true = [2, 0, 2, 2, 0, 1]
    y_pred = [0, 0, 2, 2, 0, 2]
    confusion_matrix(y_true, y_pred)
    
    array([[2, 0, 0],
           [0, 0, 1],
           [1, 0, 2]])
    

    解释如下:

    对于属于第 0 类的示例,estimator 预测其中的 100% 正确 (2/2)。
    对于属于第 1 类的示例,估计器 100% 错误,因为它预测了第 2 类的唯一示例。
    对于属于 2 类的示例,估计器的正确率为 66% (2/3),因为它预测 2 个示例属于 2 类,1 个示例属于 0 类。

    对于二元分类

    y_true = [1, 0, 1, 0, 0, 1]
    y_pred = [1, 0, 1, 1, 0, 1]
    
    cm = confusion_matrix(y_true, y_pred)
    print cm
    
    tp = float(cm[0][0])/np.sum(cm[0])
    tn = float(cm[1][1])/np.sum(cm[1])
    
    print tp
    print tn
    
    [[2 1]
     [0 3]]
    0.666666666667
    1.0
    

    关于您的GridSearchCV中使用的参数,您可以在grid_scores_属性中找到它们。

    【讨论】:

      猜你喜欢
      • 2015-09-28
      • 2016-02-03
      • 2015-07-22
      • 1970-01-01
      • 2022-01-17
      • 2018-07-24
      • 2017-01-25
      • 2021-11-15
      相关资源
      最近更新 更多