您好我在R。
中并行化 cforest 时遇到问题我一直在尝试使用 cforest 功能 party 包创建分类模型。我希望这可以在我的计算机上的几个核心中并行运行。我已经使用 randomForest 算法结合 .combine 和 foreach 成功完成了这项工作:
library(doParallel)
library(foreach)
library(randomForest)
library(party)
cl <- (5)
registerDoParallel(cl)
set.seed(1234)
abs_pos_dat_all <- read.csv('all_abs_pos_predictors_3_20_13_for_R.txt');
abs_pos_dat <- abs_pos_dat_all[1:10000,]
train_test_indices <- sample(2,nrow(abs_pos_dat), replace=TRUE, prob=c(.7,.3));
ref_polarity_dat <- read.table('ref_polarity_3_20_13_for_R.txt');
ref_polarity_dat <- factor(ref_polarity_dat[1:10000,])
ref_polarity_train <- ref_polarity_dat[train_test_indices==1]
abs_pos_train[,1] <- ordered(abs_pos_train[,1], labels = c("Buried","Part buried","Exposed"))
abs_pos_train[,2] <- ordered(abs_pos_train[,2], labels = c("Helix","Strand","Other"))
Flank_FA_labels <- c("bur bur","bur part","part part","bur exp","part exp", "exp exp")
Flank_Struc_labels <- c("helix helix","helix strand","strand strand","helix other","strand other", "other other")
Flank_Polarity_labels <- c("polar polar", "polar nonpolar", "non polar non polar" )
for(i in 1:length(Flank_FA_labels)){
abs_pos_train[,i] <- ordered(abs_pos_train[,2+i], labels = Flank_FA_labels)
abs_pos_train[,8+i] <- ordered(abs_pos_train[,8+i], labels = Flank_Polarity_labels)
abs_pos_train[,14+i] <- ordered(abs_pos_train[,14+i], labels = Flank_Struc_labels)
}
colnames(abs_pos_train) <- c("ref_FA", "ref_struc", "Np1Flank_FA", "Np2Flank_FA", "Np3Flank_FA", "Np4Flank_FA", "Np5Flank_FA", "Np6Flank_FA", "Np1Flank_Struc", "Np2Flank_Struc", "Np3Flank_Struc", "Np4Flank_Struc", "Np5Flank_Struc", "Np6Flank_Struc", "Np1Flank_P_NP","Np2Flank_P_NP", "Np3Flank_P_NP", "Np4Flank_P_NP", "Np5Flank_P_NP", "Np6Flank_P_NP")
abs_pos_random_forest <<- foreach(ntree=rep(100, 5), .combine=combine, .packages='randomForest') %dopar% randomForest(ref_polarity_train~.,data = abs_pos_train, ntree=ntree)
但是,当我使用与 cforest 相同的语法时,我收到以下错误:
abs_pos_inference_random_forest <<- foreach(ntree=rep(20, 6),
.combine=combine , .packages='party') %dopar% cforest(ref_polarity_train~.,
data = abs_pos_train, controls = cforest_unbiased(ntree=ntree, mtry = 1))
error calling combine function:
<simpleError in fun(result.1, result.2):
Argument must be a list of randomForest objects>
我无法弄清楚为什么.combine正在寻找 randomForest 对象而不是 cforest 对象,或者至少为什么.combine不能自动识别正在组合的对象,如果它们都是单个函数的输出。
答案 0 :(得分:1)
您将收到相同的错误消息:
library(randomForest)
combine(1,2,3)
可能是randomForest包已加载,因此randomForest combine
函数通过.combine
选项传递给foreach。如果combine
是一个泛型函数,其方法由randomForest和party定义,那么它可能已按预期工作。但它不是通用的;它只是randomForest包中定义的常规函数,并且尽职尽责地调用它。
我不太熟悉派对套餐,所以我不知道它是否包含一个等效功能。