Precision和Recall都能夠從下面的TP,TN,FP,FN里面計(jì)算出來惯吕。
幾個(gè)縮寫的含義:
縮寫 | 含義 |
---|---|
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: 我認(rèn)為是真的循狰,結(jié)果確實(shí)是真的
TN: 我認(rèn)為是假的,結(jié)果確實(shí)是假的
FP: 我認(rèn)為是真的,結(jié)果是假的
FN: 我認(rèn)為是假的,結(jié)果是真的
T / F: 表名我預(yù)測(cè)的結(jié)果的真假
P / N: 表名我所認(rèn)為的真還是假
image
precision和recall的進(jìn)一步解釋
image
precision和accuracy的區(qū)別
簡(jiǎn)單的來說窒篱,給定一組測(cè)量點(diǎn)的集合:
精確(precision): 所有的測(cè)量點(diǎn)到測(cè)量點(diǎn)集合的均值非常接近,與測(cè)量點(diǎn)的方差有關(guān)舶沿。就是說各個(gè)點(diǎn)緊密的聚合在一起墙杯。
準(zhǔn)確(accuracy): 所有的測(cè)量點(diǎn)到真實(shí)值非常接近。與測(cè)量點(diǎn)的偏差有關(guān)括荡。
以上兩個(gè)概念是相互獨(dú)立的高镐,因此數(shù)據(jù)點(diǎn)集合可以使accurate的,也可以使precise的畸冲,還可以都不是或者都是嫉髓。
image
二元分類問題
image
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
將二元分類指標(biāo)拓展到多類和或多標(biāo)簽問題中
image
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))
image