代码在机器学习中具有10倍交叉验证

时间:2016-02-24 04:42:30

标签: r machine-learning decision-tree cross-validation

我刚刚开始使用机器学习。我尝试使用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"

有谁知道发生了什么?非常感谢你!

1 个答案:

答案 0 :(得分:1)

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

{{1}}