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

查看:11
本文介绍了识别派对 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 并返回温度、风和臭氧的函数

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

推荐答案

你可以试试这个:

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天全站免登陆