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)
I get the following error:
Error in summary.connection(connection) : invalid connection
I would like to create in parallel models (J48). So that a model will be built for each sub dataset. For instance, for iris_dataset[[1]]
the J48 will be j48_c.models[[1]]
... and for iris_dataset[[18]]
the J48 will be j48_c.models[[18]]
.
You can run the models in the following way individually:
> 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