作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我“更新”了 caret 中的 twoClassSummary 函数,以使用 caret 函数包括阴性和阳性预测值:
testfun <- function (data, lev = NULL, model = NULL)
{
lvls <- levels(data$obs)
if (length(lvls) > 2)
stop(paste("Your outcome has", length(lvls), "levels. The
twoClassSummary() function isn't appropriate."))
requireNamespaceQuietStop("ModelMetrics")
if (!all(levels(data[, "pred"]) == lvls))
stop("levels of observed and predicted data do not match")
data$y = as.numeric(data$obs == lvls[2])
rocAUC <- ModelMetrics::auc(ifelse(data$obs == lev[2], 0,
1), data[, lvls[1]])
out <- c(rocAUC, sensitivity(data[, "pred"], data[, "obs"], lev[1]),
specificity(data[, "pred"], data[, "obs"], lev[2]),
# next 3 lines are my additions and modifications
negPredValue(data[, "obs"], data[, "pred"], lev[2]),
posPredValue(data[, "obs"], data[, "pred"], lev[1]))
names(out) <- c("ROC", "Sens", "Spec", "NPV", "PPV")
out
}
train_control <- trainControl(method = 'repeatedcv',
number = 10, repeats = 3,
summaryFunction = testfun,
classProbs = T,
savePredictions = T)
modelSvm <- train(target ~ ., data = twoClassData, trControl = train_control, method = 'svmRadial')
twoClassSummary
最佳答案
该函数不是由 caret
导出的,所以使用 caret::: requireNamespaceQuietStop
代替(或使用使用过的 library
)。
关于requireNamespaceQuietStop 在自定义 summaryFunction 插入符号中导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44837807/
我“更新”了 caret 中的 twoClassSummary 函数,以使用 caret 函数包括阴性和阳性预测值: testfun 2) stop(paste("Your outcome
我是一名优秀的程序员,十分优秀!