library(foreach)
library(doParallel)
data (iris)
### 18 sub datasets
N<-18
iris_dataset<-list()
for (i in 1:N) {iris_dataset[[i]]<-iris[sample(1:10, 1):sample(75:150, 1),]}
j48_c.models <-list()
cl<-makeCluster(8)
registerDoParallel(cl)
j48_c.models<-foreach(i=1:N, .combine='rbind') %dopar% {
library (RWeka)
J48(Species ~ ., data = iris_dataset[[i]], control = Weka_control(M = 30, C = 0.05)) }
stopCluster(cl)
我收到以下错误:
Error in summary.connection(connection) : invalid connection
我想创建并行模型(J48)。这样将为每个子数据集建立一个模型。例如,对于iris_dataset[[1]]
J48 将是j48_c.models[[1]]
... 而对于iris_dataset[[18]]
J48 将是j48_c.models[[18]]
.
您可以通过以下方式单独运行模型:
> model<-J48(Species ~ ., data = iris_dataset[[1]], control = Weka_control(M = 30, C = 0.05))
> model
J48 pruned tree
------------------
Petal.Width <= 0.6: setosa (46.0)
Petal.Width > 0.6
| Petal.Width <= 1.7: versicolor (54.0/5.0)
| Petal.Width > 1.7: virginica (36.0/1.0)
Number of Leaves : 3
Size of the tree : 5