From 841c5a2dc707a9f0eb1c60fb175d0adb309fcbae Mon Sep 17 00:00:00 2001 From: jackfrued Date: Thu, 13 Feb 2025 16:06:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B8=AD=E7=9A=84=E7=AC=94=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Day81-90/82.k最近邻算法.md | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Day81-90/82.k最近邻算法.md b/Day81-90/82.k最近邻算法.md index ca12b69..36ffa0f 100644 --- a/Day81-90/82.k最近邻算法.md +++ b/Day81-90/82.k最近邻算法.md @@ -241,45 +241,40 @@ model.score(X_test, y_test) | **实际为未患病** | 30(FP) | 870(TN) | 1. **准确率**(Accuracy)。 - $$ - \text{准确率} = \frac{\text{TP} + \text{TN}}{\text{TP} + \text{FP} + \text{FN} + \text{TN}} + \text{Accuracy} = \frac{\text{TP} + \text{TN}}{\text{TP} + \text{FP} + \text{FN} + \text{TN}} $$ 上面的例子,模型预测的准确率为: $\small{\frac{80 + 870}{80 + 30 + 20 + 870} = \frac{950}{1000} = 0.95}$ 。 - + 2. **精确率**(Precesion)。精确率用于衡量在所有被预测为正类的样本中,实际上属于正类的比例,通常也被称为查准率。 - $$ - \text{精确率} = \frac{\text{TP}}{\text{TP} + \text{FP}} + \text{Precesion} = \frac{\text{TP}}{\text{TP} + \text{FP}} $$ 上面的例子,模型预测的精确率为: $\small{\frac{80}{80 + 30} = \frac{80}{110} = 0.73}$ 。 - + 3. **召回率**(Recall)。召回率用于衡量在所有实际为正类的样本中,被模型正确预测为正类的比例,通常也被称为查全率或真正例率(True Positive Rate)。 - $$ - \text{召回率} = \frac{\text{TP}}{\text{TP} + \text{FN}} + \text{Recall} = \frac{\text{TP}}{\text{TP} + \text{FN}} $$ 上面的例子,模型预测的召回率为: $\small{\frac{80}{80 + 20} = \frac{80}{100} = 0.8}$ 。 - + 4. **F1 分数**(F1 Score)。F1 分数是精确率和召回率的调和平均数,它在精确率和召回率之间寻求一个平衡,尤其适用于在两者之间有权衡的情况。 - $$ - \text{F1分数} = \frac{2}{\frac{1}{\text{精确率}} + \frac{1}{\text{召回率}}} = 2 \times \frac{\text{精确率} \times \text{召回率}}{\text{精确率} + \text{召回率}} + \text{F1 Score} = \frac{2}{\frac{1}{\text{Precision}} + \frac{1}{\text{Recall}}} = 2 \times \frac{\text{Precision} \times \text{Recall}}{\text{Precesion} + \text{Recall}} $$ 上面的例子,模型预测的F1 分数为: $\small{2 \times \frac{0.7273 * 0.8}{0.7273 + 0.8} = 0.76}$ 。 - + 5. **特异度**(Specificity)和**假正例率**(False Positive Rate)。特异度用于衡量的是在所有实际为负类的样本中,被模型正确预测为负类的比例,类似于召回率,只不过针对的是负类样本。 - $$ - \text{特异度} = \frac{\text{TN}}{\text{TN} + \text{FP}} + \text{Specificity} = \frac{\text{TN}}{\text{TN} + \text{FP}} $$ $$ - \text{假正例率} = 1 - \text{特异度} + \text{False Positive Rate} = 1 - \text{Specificity} $$ 上面的例子,模型预测的特异度为: $\small{\frac{870}{870 + 30} = \frac{870}{900} = 0.97}$ 。