歡迎您光臨本站 註冊首頁

基於python實現ROC曲線繪製廣場解析

←手機掃碼閱讀     wooen @ 2020-06-29 , reply:0

ROC

結果

源數據:鳶尾花數據集(僅採用其中的兩種類別的花進行訓練和檢測)

Summary

features:['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']

實例:[5.1, 3.5, 1.4, 0.2]
 target:'setosa' 'versicolor' (0 , 1)

採用迴歸方法進行擬合得到參數和bias

model.fit(data_train, data_train_label)

對測試數據進行預測得到概率值

res = model.predict(data[:100])

與訓練集labels匹配後進行排序(從大到小)

      pred labels  68 0.758208    1  87 0.753780    1  76 0.745833    1  50 0.743156    1  65 0.741676    1  75 0.739117    1  62 0.738255    1  54 0.737036    1  52 0.733625    1  77 0.728139    1  86 0.727547    1  74 0.726261    1  58 0.725150    1  71 0.724719    1  36 0.724142    0  14 0.723990    0  31 0.721648    0  41 0.720308    0  72 0.717723    1  79 0.712833    1  97 0.705148    1  51 0.702838    1  35 0.702203    0  98 0.701731    1  92 0.701106    1  82 0.700661    1  53 0.700465    1  18 0.699350    0  16 0.696915    0  64 0.693333    1  ..    ...   ...  33 0.658937    0  96 0.656761    1  30 0.656279    0  57 0.655673    1  4  0.652616    0  85 0.648620    1  59 0.648586    1  19 0.646965    0  70 0.646262    1  88 0.644482    1  8  0.643191    0  38 0.642704    0  3  0.640933    0  55 0.640630    1  47 0.640444    0  95 0.639552    1  13 0.639050    0  22 0.638485    0  29 0.635590    0  90 0.634376    1  37 0.632224    0  6  0.631119    0  46 0.630037    0  11 0.629718    0  66 0.627807    1  42 0.624795    0  44 0.621703    0  32 0.614932    0  24 0.603874    0  84 0.603249    1

 

計算訓練集中正確的個數與非正確的個數
 

運用一下的算式進行TPR和FPR的計算

  index = 0  for i in sorted_mat.values:    if i[1] == 0:      TPR.append(TPR[index])      FPR.append(FPR[index] + 1.0/F_num)    else:      TPR.append(TPR[index] + 1.0/T_num)      FPR.append(FPR[index])    index += 1

 

最後進行TPR和FPR的描繪

                                                       

   


[wooen ] 基於python實現ROC曲線繪製廣場解析已經有222次圍觀

http://coctec.com/docs/python/shhow-post-240289.html