【发布时间】:2014-09-25 22:16:14
【问题描述】:
我在运行此代码时收到警告,我想要 11 行结果,但结果只有 1 行
我应该插入for循环吗?如果是这样,你们可以在代码中指定它吗?
另外,我试过(i in 1:length(alpha)),但也没有用。
require(useful)
iris1<-iris[1:100,]
acsx<-build.x(Species~ Sepal.Length+ Sepal.Width+ Petal.Length +Petal.Width-
1,data=iris1,contrasts=FALSE)
acsy<-build.y(Species~ Sepal.Length+ Sepal.Width+ Petal.Length +Petal.Width-1,data=iris1)
theFolds<-sample(rep(x=1:5,length.out=nrow(acsx)))
alphas<-seq(from=0.5, to =1, by=0.05)
result<-foreach(i=1:length(alphas), .errorhandling="remove",
.inorder=FALSE, multicombine=TRUE,
.export=c("acsx","acsy","alphas","theFolds"),
.packages="glmnet") %dopar%
{ for(i in 1:length(alphas) )
print(alphas[i])
cv.glmnet(x=acsx,y=acsy,family="binomial",nfold=5,foldid=theFolds, alpha=alphas[i])
}
警告信息:
在 e$fun(obj, substitution(ex), parent.frame(), e$data) 中: 已经导出变量:acsx、acsy、alphas、theFolds`
【问题讨论】:
-
您的示例不可重现,因此难以测试。请添加示例数据(或使用
iris构建模型)并显示运行代码所需的所有库。 -
首先,这是一个警告,而不是错误,所以如果您的代码失败,那不是原因。它只是在说你在重复导出东西;可能每个
i值一次。 -
感谢 cmets。我只是用数据编辑代码,你能告诉我如何生成 11 个观察值吗?
标签: r foreach parallel-processing iterator warnings