![](/img/trans.png)
[英]How do I extract positive and negative outliers from boxplots into separate variables in R?
[英]How does R judges positive and negative factor variables?
我想做一个二元分类,一个级别是“顶部”,另一个级别是“底部”。 我在 h2o 包中使用了 gbm 并将“底部”作为正类,将“顶部”作为负类。 这是我的代码:
fit <- h2o.gbm(x = regr.var, y = max.var,
training_frame = ddd,
nfolds = 10,
distribution = 'multinomial',
balance_classes = TRUE)
pred <- as.data.frame(h2o.predict(fit, newdata = eee))
threshold <- 0.5
pred1 <- factor( ifelse(pred[, 'top'] > threshold, 'top', 'bottom') )
err.res<-confusionMatrix(pred1 , hh$score_class)
err.res
结果如下:
Confusion Matrix and Statistics
Reference
Prediction bottom top
bottom 420 123
top 1 6
Accuracy : 0.7745
95% CI : (0.7373, 0.8088)
No Information Rate : 0.7655
P-Value [Acc > NIR] : 0.3279
Kappa : 0.0657
Mcnemar's Test P-Value : <2e-16
Sensitivity : 0.99762
Specificity : 0.04651
Pos Pred Value : 0.77348
Neg Pred Value : 0.85714
Prevalence : 0.76545
Detection Rate : 0.76364
Detection Prevalence : 0.98727
Balanced Accuracy : 0.52207
'Positive' Class : bottom
但我想正确预测更多的“顶部”。 我尝试将阈值更改为 0.3,效果更好。 但是,我是否应该在拟合过程中进行更改以对“ROC”等“顶级”指标进行更多预测? 我应该将“顶部”翻转为正类,将“底部”翻转为负类,我该如何更改?
我认为您想在函数中添加“正”参数:
err.res <- confusionMatrix(pred1, hh$score_class, positive="top")
我建议使用 h2o.confustionMatrix 并使用它来创建不同阈值的矩阵。
前任。 h2o.confusionMatrix(object = fit, threshold = 0.3)
谢谢,
阿夫尼
如果你想直接在 h2o 中声明一个正类,为了有正确的度量(使用h2o.confusionMatrix
, h2o.performance
等),你可以使用函数h2o.relevel
。 例如在您的示例中,您应该在模型训练之前添加:
ddd[max.var] <- h2o.relevel(ddd[max.var],'bottom')
(默认情况下,我相信 h2o 根据字母顺序决定正类,并且在您的示例中 h2o 度量函数应该立即起作用)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.