【发布时间】:2016-02-08 13:55:02
【问题描述】:
我正在努力确保在我的树对象和用于预测的测试集中,我的类型因子的所有特征(就所有可能的因子级别而言)都得到了充分的表示。
for (j in 1:length(predictors)){
if (is.factor(Test[,j])){
ct [[names(predictors)[j]]] <- union(ct$xlevels[[names(predictors)[j]]], levels(Test[,c(names(predictors)[j])]))
}
}
但是,对于对象 ct(来自包方的 ctree),我似乎无法理解如何访问功能的因子级别,因为我遇到了错误
Error in ct$xlevels : $ operator not defined for this S4 class
【问题讨论】:
-
party 使用 s4 方法,你没有用 $ 索引,你应该阅读
?'BinaryTree-class' -
可能在
partykit中使用ctree的新S3 实现更容易用于您的目的...它还附带更多文档。
标签: r decision-tree party