gpt4 book ai didi

r - 机器学习中具有 10 倍交叉验证的代码

转载 作者:行者123 更新时间:2023-11-30 09:54:54 26 4
gpt4 key购买 nike

我刚刚开始从事机器学习工作。我尝试使用 C5.0 模型运行 10 折交叉验证。我要求代码返回 kappa 值。

folds = createFolds(mdd.cohort1$edmsemmancomprej, k=10)
str(folds)
mdd.cohort1_train = mdd.cohort1[-folds$Fold01,]
mdd.cohort1_test = mdd.cohort1[folds$Fold01,]
library(caret)
library(C5.0)
library(irr)
set.seed(123)
folds = createFolds(mdd.cohort1$edmsemmancomprej, k=10)

cv_results = lapply(folds, function(x)
{mdd.cohort1_train = mdd.cohort1[-x, ]
mdd.cohort1_test = mdd.cohort1[x, ]
mdd.cohort1_model = C5.0(edmsemmancomprej ~., data = mdd.cohort1_train)
mdd.cohort1_pred = predict(mdd.cohort1_model, mdd.cohort1_test)
mdd.cohort1_actual = mdd.cohort1_test$edmsemmancomprej
kappa = kappa2(data.frame(mdd.cohort1_actual, mdd.cohort1_pred))$value return(kappa)})

给出以下错误消息:

Error: unexpected symbol in:
"mdd.cohort1_actual = mdd.cohort1_test$edmsemmancomprej
kappa = kappa2(data.frame(mdd.cohort1_actual, mdd.cohort1_pred))$value return"

有谁知道发生了什么吗?提前非常感谢您!

最佳答案

如果没有可重现的示例,这有点困难,但我认为最后一行的返回共享是原因。为了便于阅读,我对您的代码进行了一些重新格式化

library(caret)
library(C5.0)
library(irr)

folds = createFolds(mdd.cohort1$edmsemmancomprej, k=10)

str(folds)

mdd.cohort1_train = mdd.cohort1[-folds$Fold01,]
mdd.cohort1_test = mdd.cohort1[folds$Fold01,]

set.seed(123)
folds = createFolds(mdd.cohort1$edmsemmancomprej, k=10)

cv_results = lapply(folds, function(x) {
mdd.cohort1_train = mdd.cohort1[-x, ]
mdd.cohort1_test = mdd.cohort1[x, ]
mdd.cohort1_model = C5.0(edmsemmancomprej ~., data = mdd.cohort1_train)
mdd.cohort1_pred = predict(mdd.cohort1_model, mdd.cohort1_test)
mdd.cohort1_actual = mdd.cohort1_test$edmsemmancomprej
kappa = kappa2(data.frame(mdd.cohort1_actual, mdd.cohort1_pred))$value
return(kappa)
})

关于r - 机器学习中具有 10 倍交叉验证的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35593418/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com