【发布时间】: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的结果,您不需要对列进行子集化