识别参与方ctree nodel中的所有不同变量 [英] Identify all distinct variables within party ctree nodel

查看:92
本文介绍了识别参与方ctree nodel中的所有不同变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Party R包中的ctree函数.我想确定树中使用的所有预测变量,以减少用于进一步分析的data.frame维度.例如:

I am using ctree function within party R package. I would like to idenfiy all predictors that are used within the tree in order to reduce the data.frame dimension used for further analyses. For example:

library(ctree)
data(ozone)
myModel<-ctree(Ozone~., data=na.omit(airquality))
plot(myModel)

我想要一个接收myModel并返回Temp,Wind和Ozone的函数

I would like a function receiving myModel and returning Temp, Wind and Ozone

推荐答案

您可以尝试使用此方法:

You can try using this:

getUsefulPredictors<-function(x){
  flatTree<-unlist(x@tree)
  pred<-unique(flatTree[grepl("*variableName",names(flatTree))])
  return(pred)
}

它压扁树木并寻找名称中具有variableName的元素

It flattens the trees and looks for the elements having variableName in their name

在模型上运行,它将返回:

Run on your model it returns:

getUsefulPredictors(myModel)
#[1] "Temp" "Wind"

这篇关于识别参与方ctree nodel中的所有不同变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆