varimp(R partykit)返回条件重要性设置的错误

时间:2018-05-23 21:29:22

标签: r machine-learning random-forest feature-selection party

首先,我通过

构建了一个模型
cf1 <- cforest(y~., data = DATA, strata = DATA$y,
           ntree = 200L, mtry = 10)

这里考虑到数据集非常不平衡(y=1占整个观察的7%),所以我在这里添加strata以确保在装袋中不会忽略y=1的观察。就混淆矩阵而言,cf1正常工作。但是,当我尝试通过

实现功能选择时
cf1.imp_cond <- varimp(cf1, conditional = TRUE)

返回

Error in x[strata == s] <- .resample(x[strata == s]) : 
NAs are not allowed in subscripted assignments

我无法弄清楚这个错误意味着什么。有人以前见过这个吗?

----更新

以下是我正在使用的原始数据集中的操作test data。这是代码

cf2 <- cforest(X5_years_survival~., data = test, strata = X5_years_survival,
           ntree = 200L, mtry = 6)
cf2.imp_cond <- varimp(cf2, conditional = TRUE)

仍然,我有错误:

Error in x[strata == s] <- .resample(x[strata == s]) : 
NAs are not allowed in subscripted assignments

---更新

应用kidids_node功能时会发生错误。

1 个答案:

答案 0 :(得分:0)

事实是,如果我保留所有integer类型的协变量,而不是按as.factor进行转换,则应用varimp不会出错。