Identify all distinct variables within party ctree nodel

前端 未结 2 1664
逝去的感伤
逝去的感伤 2021-01-25 03:57

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 furth

2条回答
  •  我在风中等你
    2021-01-25 04:44

    You can try using this:

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

    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"
    

提交回复
热议问题