Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 灵敏度太低_Python_Machine Learning_Scikit Learn_Logistic Regression_Confusion Matrix - Fatal编程技术网

Python 灵敏度太低

Python 灵敏度太低,python,machine-learning,scikit-learn,logistic-regression,confusion-matrix,Python,Machine Learning,Scikit Learn,Logistic Regression,Confusion Matrix,我正在处理逻辑回归分析。数据中目标值为0的患者人数为2000人,目标值为1的患者人数为188人。虽然总准确度为92,但灵敏度极低。这可能是因为阶级不平衡吗?结果如下: LogisticRegression(class_weight={0:1, 1:10}) 分数: test score: 0.90 train score: 0.92 TRUE POSITIVE: 498 FALSE POSITIVE: 47 TRUE NEGATIVE: 2 FALSE NEGATIVE: 3 Ov

我正在处理逻辑回归分析。数据中目标值为0的患者人数为2000人,目标值为1的患者人数为188人。虽然总准确度为92,但灵敏度极低。这可能是因为阶级不平衡吗?结果如下:

LogisticRegression(class_weight={0:1, 1:10})
分数:

test score: 0.90
train score: 0.92
TRUE POSITIVE:  498
FALSE POSITIVE:  47
TRUE NEGATIVE:  2
FALSE NEGATIVE:  3
Overall Accuracy: 0.90
Sensitivity:  0.99
Specificity: 0.040

False Positive Rate:  0.959
False Discovery Rate:  0.086
Positive Predictive Value:  0.91
Negative Predictive Value:  0.4

F1 score:  0.952
Roc Auc: 0.822
混淆矩阵:

test score: 0.90
train score: 0.92
TRUE POSITIVE:  498
FALSE POSITIVE:  47
TRUE NEGATIVE:  2
FALSE NEGATIVE:  3
Overall Accuracy: 0.90
Sensitivity:  0.99
Specificity: 0.040

False Positive Rate:  0.959
False Discovery Rate:  0.086
Positive Predictive Value:  0.91
Negative Predictive Value:  0.4

F1 score:  0.952
Roc Auc: 0.822
一些指标:

test score: 0.90
train score: 0.92
TRUE POSITIVE:  498
FALSE POSITIVE:  47
TRUE NEGATIVE:  2
FALSE NEGATIVE:  3
Overall Accuracy: 0.90
Sensitivity:  0.99
Specificity: 0.040

False Positive Rate:  0.959
False Discovery Rate:  0.086
Positive Predictive Value:  0.91
Negative Predictive Value:  0.4

F1 score:  0.952
Roc Auc: 0.822

当然,这是由于你们班的不平衡

由于这种不平衡,您的模型更倾向于预测几乎每一个实例的正值,因为模型更容易这样做

要解决这个问题,有很多策略,例如:

  • 如果要对模型进行交叉验证,请进行分层折叠

  • 你可以试着对你的大多数班级进行抽样调查

  • 您可以尝试向上采样少数类(有许多生成方法可以从少数类生成新数据:)

  • 更改模型参数。使用LogistRegression,您通常可以为您的类赋予权重,以惩罚少数类的严重错误。实现取决于您使用的语言

scikit-learn
中,您可以执行以下操作:

LogisticRegression(class_weight={0:1, 1:10})
在上面的示例中,我给类“1”的错误比类“0”的错误大10倍

注意:此权重是模型的超参数,因此应进行验证


无论如何,如果你想要一个更广泛的答案,请检查我的答案。“模型=逻辑回归(C=0.1,类权重={0:1,1:10},最大iter=10000)”解决了我的问题。@Muratşııkalan不客气。别忘了接受最好的答案:)我投票结束这个问题,因为它不是关于中定义的编程,而是关于ML理论和方法。