AI/ML
使用套件:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_fscore_support.html
這篇舉例說明頗清楚:
https://blog.csdn.net/jmh1996/article/details/114935105
我也來舉個例子:
Notations
看表格解釋
d1 | d2 | d3 | d4 | d5 | d6 | d7 | d8 | d9 | d10 | |
---|---|---|---|---|---|---|---|---|---|---|
gt | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 |
pred | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 |
對於+ | TN | FP | TN | TP | FN | TN | TN | FP | TN | TP |
對於- | TP | FN | TP | TN | FP | TP | TP | FN | TP | TN |
統計一下
對於+ 當中 \(TP: 2, FP: 2, TN: 5, FN: 1\)
對於- 當中 \(TP:5, FP:1, TN:2, FN:2\)
根據定義
\[precision=\frac{TP}{TP+FP} \hspace{0.5cm} recall=\frac{TP}{TP+TN}\]
\[F1\_score=2\frac{precision\times recall}{precision+recall}\]
在 sklearn.metrics 的 precision_recall_fscore_support 裡所謂的 binary average 模式
就是只看對於+(陽性樣本)的 precision, recall, fscore 值
計算出來得到
\[bin\_precision(+)=\frac{2}{2+2}=0.5 \hspace{0.5cm} bin\_recall(+)=\frac{2}{2+1}=0.6666\]
F1 值為這兩個的平均,在此就不贅述
macro 就是把對於正樣本(+) 的結果與對於負樣本(-) 的結果分別算出來後,做平均
正樣本的結果已經在上一段落算完,因此我們還需要計算
對於-(陰性樣本)的precision, recall, fscore 值計算如下
\[bin\_precision(-)=\frac{5}{5+1}=0.8333 \hspace{0.5cm} bin\_recall(-)=\frac{5}{5+2}=0.7142\]
接著就可以計算 macro average 版本的 precision, recall, fscroe 值計算如下
\[macro\_precision=\frac{0.5+0.8333}{2}=0.6666 \hspace{0.5cm} macro\_recall=\frac{0.6666+0.7142}{2}=0.6904\]
micro avg 是把上述的
把以上兩個分類觀點觀察到的 TP, FP, TN, FN 都做加總之後再做計算:
\(sum\_TP:2+5=7\) , \(sum\_FP:2+1=3\) , \(sum\_TN:5+2=7\) , \(sum\_FN:2+1=3\)
再根據定義計算出 micro average 版本的 precision, recall, fscore 值計算如下
\[micro\_precision=\frac{7}{7+3}=0.7 \hspace{0.5cm} micro\_recall=\frac{7}{7+3}=0.7\]
報告完畢
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing