我想创建一个用于拟合数据的模型列表。
以下代码
models = list("naiveBayes","rf")
for(model_name in models){
print(model_name)
formual = V35 ~ .
model = model_name(formual,data=train)
}
我得到的错误
Error: could not find function "model_name"
答案 0 :(得分:1)
创建一个函数变量:
models = c("naiveBayes","rf")
for(model_name in models){
print(model_name)
formual = V35 ~ .
m <- match.fun(model_name)
m(formual,data=train)
}