【问题标题】:ROC curve for discrete classifier using scikit learn使用 scikit learn 的离散分类器的 ROC 曲线
【发布时间】:2018-07-30 22:09:57
【问题描述】:

我在概念上理解 scikit learn 中的 ROC 函数如何生成真阳性率和假阳性率时遇到了一点麻烦。我使用 BC scikit 学习数据并围绕 2 个随机特征构建了一个决策树。

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn import tree
import numpy as np

data = load_breast_cancer()
X = data.data[:, [1,3]]
y = data.target

# Splitting data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33,random_state=0)

# Training tree
bc_tree = tree.DecisionTreeClassifier(criterion="entropy").fit(X_train, y_train)

# Predictions
bc_pred = bc_tree.predict(X_test)
# Score
bc_tree.score(X_test, y_test)

# Confusion matrix
from sklearn.metrics import confusion_matrix
metrics.confusion_matrix(y_test, bc_pred) # True positive = 0.83

# ROC curve
fpr_tree, tpr_tree, thresholds_tree = metrics.roc_curve(y_test, bc_pred)

# True positive rate ROC
tpr_tree # 0.91

混淆矩阵如下所示:

[[ 55,  12]
[ 11, 110]]

根据我的计算,真阳性率为:

55/(55+11) = .83

根据scikit learn实现的ROC曲线,真阳性率为0.92。它是如何计算这个数字的,为什么我的计算不匹配?我错过了什么?

【问题讨论】:

    标签: python scikit-learn classification roc


    【解决方案1】:

    因为你推断的混淆矩阵是错误的。

    confusion_matrix 返回的矩阵格式为

          0   TN   FP
    True
          1   FN   TP
    
               0    1
             Predicted
    

    所以根据TPR的公式,这个值应该是110/ (110+11) = 0.9090...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-23
      • 2013-04-30
      • 2016-08-24
      • 2013-10-08
      • 2019-04-19
      • 2018-01-20
      • 2016-09-09
      • 2016-02-06
      相关资源
      最近更新 更多