我在R中使用了caret进行逻辑回归:
ctrl <- trainControl(method = "repeatedcv", number = 10, repeats = 10,
savePredictions = TRUE)
mod_fit <- train(Y ~ ., data=df, method="glm", family="binomial",
trControl = ctrl)
print(mod_fit)
默认输出的度量是准确率和Cohen kappa。我希望能提取匹配度量,比如灵敏度、特异度、阳性预测值等,但我找不到简单的方法。最终模型已经提供,但据文档所述,它是在所有数据上训练的,因此我无法用它来进行新的预测。
混淆矩阵可以计算所有所需的参数,但将其作为汇总函数传递并不起作用:
ctrl <- trainControl(method = "repeatedcv", number = 10, repeats = 10,
savePredictions = TRUE, summaryFunction = confusionMatrix)
mod_fit <- train(Y ~ ., data=df, method="glm", family="binomial",
trControl = ctrl)
Error: `data` and `reference` should be factors with the same levels.
13.
stop("`data` and `reference` should be factors with the same levels.",
call. = FALSE)
12.
confusionMatrix.default(testOutput, lev, method)
11.
ctrl$summaryFunction(testOutput, lev, method)
除了准确度和kappa之外,是否有一种方法可以提取这些信息,或者在caret train返回的train_object中找到它们?
谢谢!
caret::train()
之前,你是否将数据拆分为训练组和测试组了呢? - Len Greski