1

我想做一个二进制分类,一个级别是“top”,另一个是“bottom”。我在 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”指标等“顶部”做出更多预测?我应该将“顶部”翻转为正类,将“底部”翻转为负类,我该如何改变它?

4

3 回答 3

1

我认为您想将“积极”参数添加到您的函数中:

err.res <- confusionMatrix(pred1, hh$score_class, positive="top")
于 2016-06-29T00:55:24.677 回答
0

如果你想直接在 h2o 中声明一个正类,为了有正确的度量(withh2o.confusionMatrixh2o.performance),你可以使用函数h2o.relevel. 例如在您的示例中,您应该在模型训练之前添加:

ddd[max.var] <- h2o.relevel(ddd[max.var],'bottom')

(默认情况下,我相信 h2o 会根据字母顺序决定正类,在您的示例中,h2o 度量函数应该立即起作用)

于 2018-08-22T16:30:40.627 回答
0

我建议使用 h2o.confustionMatrix 并使用它来创建不同阈值的矩阵。

前任。h2o.confusionMatrix(object = fit, threshold = 0.3)

谢谢,

阿维尼

于 2015-11-18T23:15:39.363 回答