解答と解説を表示
<h4>F1スコアとは?</h4>
<p>F1スコアは、分類モデルの性能評価指標の一つで、特に<strong>適合率 (Precision)</strong> と<strong>再現率 (Recall)</strong> のバランスを取りたい場合に用いられます。不均衡データのように精度だけでは評価が難しい場合や、適合率と再現率のどちらか一方だけを最大化するのが適切でない場合に有用です。</p>
<h4>適合率と再現率の調和平均</h4>
<p>F1スコアは、適合率と再現率の<strong>調和平均 (Harmonic Mean)</strong> で計算されます。</p>
<div class="formula">
$ F1 = 2 \times \frac{\text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}} = \frac{2 \times TP}{2 \times TP + FP + FN}$
</div>
<p>調和平均は、値が小さい方の影響を強く受けるため、適合率と再現率の両方がバランス良く高い場合にF1スコアも高くなります。どちらか一方が極端に低いと、F1スコアも低くなります。</p>
<h4>計算ステップ</h4>
<p>混同行列: TP=80, FN=20, FP=10, TN=90</p>
<p>1. <strong>適合率 (Precision) の計算:</strong> (モデルがPositiveと予測したうち、実際にPositiveだった割合)</p>
<div class="formula">
$\text{Precision} = \frac{TP}{TP+FP} = \frac{80}{80+10} = \frac{80}{90} = \frac{8}{9}$
</div>
<p>2. <strong>再現率 (Recall) の計算:</strong> (実際のPositiveのうち、モデルがPositiveと予測できた割合)</p>
<div class="formula">
$ \text{Recall} = \frac{TP}{TP+FN} = \frac{80}{80+20} = \frac{80}{100} = \frac{4}{5}$
</div>
<p>3. <strong>F1スコアの計算:</strong></p>
<div class="formula">
$ F1 = 2 \times \frac{\text{Precision} \times \text{Recall}}{\text{Precision} + \\text{Recall}} = 2 \times \frac{(8/9) \times (4/5)}{(8/9) + (4/5)} \\\
= 2 \times \frac{32/45}{(40+36)/45} = 2 \times \frac{32/45}{76/45} \\\
= 2 \times \frac{32}{76} = \frac{16}{19} \\\
\approx 0.8421...$
</div>
<p>したがって、F1スコアは約 <strong>0.842</strong> です。</p>
<div class="key-point">
<div class="key-point-title">重要ポイント:F1スコアの活用</div>
<ul>
<li><strong>バランスの指標:</strong> 適合率と再現率のトレードオフを考慮し、両者のバランスを評価します。</li>
<li><strong>不均衡データに有効:</strong> 精度が機能しにくい不均衡データセットの評価に適しています。</li>
<li><strong>利用場面:</strong> 情報検索、固有表現抽出、医療診断支援など、偽陽性・偽陰性の両方を避けたい多くのタスクで使われます。</li>
<li><strong>一般化 (F-betaスコア):</strong> 再現率をより重視する場合は F2 スコア、適合率をより重視する場合は F0.5 スコアなど、重み付けを変えた F-beta スコアも存在します。</li>
</ul>
</div>