分類器評估方法:精確度-召回率-F度量(precision-recall-F_measures)


注:本文是人工智能研究網的學習筆記

Precision和Recall都能夠從下面的TP,TN,FP,FN里面計算出來。

幾個縮寫的含義

縮寫 含義
P condition positive
N condition negative
TP true positive (with hit)
TN true negative (with correct rejection)
FP false positive (with false alarm, Type I error)
FN false negative (with miss, Type II error)

TP: 我認為是真的,結果確實是真的
TN: 我認為是假的,結果確實是假的
FP: 我認為是真的,結果是假的
FN: 我認為是假的,結果是真的

T / F: 表名我預測的結果的真假
P / N: 表名我所認為的真還是假

precision和recall的進一步解釋

precision和accuracy的區別

簡單的來說,給定一組測量點的集合:

精確(precision): 所有的測量點到測量點集合的均值非常接近,與測量點的方差有關。就是說各個點緊密的聚合在一起。

准確(accuracy): 所有的測量點到真實值非常接近。與測量點的偏差有關。

以上兩個概念是相互獨立的,因此數據點集合可以使accurate的,也可以使precise的,還可以都不是或者都是。

二元分類問題

from sklearn import metrics
y_pred = [0, 1, 0, 0]
y_true = [0, 1, 0, 1]
print(metrics.precision_score(y_true, y_pred))   # 1.0
print(metrics.recall_score(y_true, y_pred))     # 0.5

# beta值越小,表示越看中precision
# beta值越大,表示越看中recall
print(metrics.f1_score(y_true, y_pred))   # 0.666666666667
print(metrics.fbeta_score(y_true, y_pred, beta=0.5))  # 0.833333333333
print(metrics.fbeta_score(y_true, y_pred, beta=1))    # 0.666666666667
print(metrics.fbeta_score(y_true, y_pred, beta=2))    # 0.555555555556

將二元分類指標拓展到多類和或多標簽問題中

from sklearn import metrics
y_pred = [0, 1, 2, 0, 1, 2]
y_true = [0, 2, 1, 0, 0, 1]
print(metrics.precision_score(y_true, y_pred, average='macro'))
print(metrics.recall_score(y_true, y_pred, average='micro'))    

print(metrics.f1_score(y_true, y_pred, average='weighted')) 
print(metrics.fbeta_score(y_true, y_pred, beta=0.5, average='macro'))  
print(metrics.precision_recall_fscore_support(y_true, y_pred, beta=0.5, average=None))


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM