使用Caret软件包进行机器学习时,我对Caret默认的"正面"结果选择感到震惊,即二元分类问题中结果因素的第一级.
包裹说它可以设置为替代级别.任何人都能帮助我确定积极的结果吗?
感谢您
phi*_*ver 18
看看这个例子.使用confusionMatrix从插入符号示例扩展了这一点.
lvs <- c("normal", "abnormal")
truth <- factor(rep(lvs, times = c(86, 258)),
levels = rev(lvs))
pred <- factor(
c(
rep(lvs, times = c(54, 32)),
rep(lvs, times = c(27, 231))),
levels = rev(lvs))
xtab <- table(pred, truth)
str(truth)
Factor w/ 2 levels "abnormal","normal": 2 2 2 2 2 2 2 2 2 2 ...
Run Code Online (Sandbox Code Playgroud)
因为异常是第一级,这将是默认的正类
confusionMatrix(xtab)
Confusion Matrix and Statistics
truth
pred abnormal normal
abnormal 231 32
normal 27 54
Accuracy : 0.8285
95% CI : (0.7844, 0.8668)
No Information Rate : 0.75
P-Value [Acc > NIR] : 0.0003097
Kappa : 0.5336
Mcnemar's Test P-Value : 0.6025370
Sensitivity : 0.8953
Specificity : 0.6279
Pos Pred Value : 0.8783
Neg Pred Value : 0.6667
Prevalence : 0.7500
Detection Rate : 0.6715
Detection Prevalence : 0.7645
Balanced Accuracy : 0.7616
'Positive' Class : abnormal
Run Code Online (Sandbox Code Playgroud)
要更改为正类=正常,只需在confusionMatrix中添加它.注意与先前输出的差异,差异开始出现在灵敏度和其他计算中.
confusionMatrix(xtab, positive = "normal")
Confusion Matrix and Statistics
truth
pred abnormal normal
abnormal 231 32
normal 27 54
Accuracy : 0.8285
95% CI : (0.7844, 0.8668)
No Information Rate : 0.75
P-Value [Acc > NIR] : 0.0003097
Kappa : 0.5336
Mcnemar's Test P-Value : 0.6025370
Sensitivity : 0.6279
Specificity : 0.8953
Pos Pred Value : 0.6667
Neg Pred Value : 0.8783
Prevalence : 0.2500
Detection Rate : 0.1570
Detection Prevalence : 0.2355
Balanced Accuracy : 0.7616
'Positive' Class : normal
Run Code Online (Sandbox Code Playgroud)