【问题标题】:How to get test data ROC plot from MLeval如何从 MLeval 获取测试数据 ROC 图
【发布时间】:2021-04-26 00:19:58
【问题描述】:

我正在尝试使用 MLevals 包返回测试数据集的 ROC 曲线。

  # Load data 
  train <- readRDS(paste0("Data/train.rds"))
  test <- readRDS(paste0("Data/test.rds"))
  
  # Create factor class
  train$class <- ifelse(train$class == 1, 'yes', 'no')
 

  # Set up control function for training
  ctrl <- trainControl(method = "cv",
                       number = 5, 
                       returnResamp = 'none',
                       summaryFunction = twoClassSummary(),
                       classProbs = T,
                       savePredictions = T,
                       verboseIter = F)
  
  gbmGrid <-  expand.grid(interaction.depth = 10,
                          n.trees = 18000,                                          
                          shrinkage = 0.01,                                         
                          n.minobsinnode = 4) 
  
  # Build using a gradient boosted machine
  set.seed(5627)
  gbm <- train(class ~ .,
               data = train,
               method = "gbm",
               metric = "ROC",
               tuneGrid = gbmGrid,
               verbose = FALSE,
               trControl = ctrl) 

# Predict results - 
  pred <- predict(gbm, newdata = test, type = "prob")[,"yes"]
  roc <- evalm(data.frame(pred, test$class))

我使用了以下帖子,ROC curve for the testing set using Caret package, 尝试使用 MLeval 从测试数据中绘制 ROC,但我收到以下错误消息:

MLeval:机器学习模型评估 输入:观察到的标签的概率数据框 名称错误(x)

有人可以帮忙吗?谢谢。

【问题讨论】:

  • 嘿,如果您阅读了您引用的帖子,概率应该是predict 的结果,您不需要对列进行子集化

标签: r r-caret roc gbm


【解决方案1】:

请提供带有样本数据的可重现示例,以便我们可以复制错误并测试解决方案(即,我们无法访问 train.rdstest.rds)。

不过,以下内容可能会解决您的问题。

pred <- predict(gbm, newdata = test, type = "prob")
roc <- evalm(data.frame(pred, test$class))

【讨论】:

  • 没问题,很高兴它有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-04
相关资源
最近更新 更多