代码之家  ›  专栏  ›  技术社区  ›  Dr. Fabien Tarrade

为什么roc\u曲线对于某些类的阈值(2.0)返回一个附加值?

  •  1
  • Dr. Fabien Tarrade  · 技术社区  · 7 年前

    我使用的是python3.5.2和sklearn 0.19.1

    我有一个多类问题(3类),我正在使用 RandomForestClassifier 19独特 predict_proba 价值观:

    {0.0,
    0.6666666666666666,
    0.6736189855024448,
    0.6773290780865037,
    0.7150826826468751,
    0.7175236925236925,
    0.7775446850962057,
    0.8245648135911781,
    0.8631035080004867,
    0.8720525244880196,
    0.8739595855873906,
    0.8787152225755167,
    0.9289844333343654,
    0.954439314892936,
    0.9606503912532541,
    0.9771342285323964,
    0.9883370916703461,
    0.9957401423931763,
    1.0}
    

    roc_curve 我期望roc曲线的点数和概率的唯一值相同。这只适用于三个班级中的两个!

    当我看到门槛时 功能:

    fpr, tpr, proba = roc_curve(....)

    我看到的精确值与概率列表中的值相同+一个新值2.0!

    [2.,
    1.,
    0.99574014,
    0.98833709,
    0.97713423,
    0.96065039,
    0.95443931,
    0.92898443,
    0.87871522,
    0.87395959,
    0.87205252,
    0.86310351,
    0.82456481,
    0.77754469,
    0.71752369,
    0.71508268,
    0.67732908,
    0.67361899,
    0.66666667,
    0. ]
    

    为什么会返回新的阈值2.0?我在文档中没有看到任何与此相关的内容。

    你知道吗?我错过了一些东西

    1 回复  |  直到 7 年前
        1
  •  4
  •   zdgriffith    7 年前

    roc_curve fpr[0] , tpr[0] )总是(0,0)。如果不是这样,则创建一个具有任意值的新阈值 max(y_score)+1 . 相关代码来自 the source

    thresholds : array, shape = [n_thresholds]
        Decreasing thresholds on the decision function used to compute
        fpr and tpr. `thresholds[0]` represents no instances being predicted
        and is arbitrarily set to `max(y_score) + 1`.
    

    if tps.size == 0 or fps[0] != 0:
        # Add an extra threshold position if necessary
        tps = np.r_[0, tps]
        fps = np.r_[0, fps]
        thresholds = np.r_[thresholds[0] + 1, thresholds]
    

    1.0 那是不正确的分类。