How to extract the splitting rules for the terminal nodes of ctree()

前端 未结 1 366
失恋的感觉
失恋的感觉 2021-01-06 16:35

I have a data set with 6 categorical variables with levels ranging from 5 to 28. I have obtained an output from ctree() (party package) with 17 terminal nodes. I ha

相关标签:
1条回答
  • 2021-01-06 17:29

    I would recommend to use the new partykit implementation of ctree() rather than the old party package, then you can use the function .list.rules.party(). This is not officially exported, yet, but can be leveraged to extract the desired information.

    library("partykit")
    airq <- subset(airquality, !is.na(Ozone))
    ct <- ctree(Ozone ~ ., data = airq)
    partykit:::.list.rules.party(ct)
    ##                                      3                                      5 
    ##             "Temp <= 82 & Wind <= 6.9" "Temp <= 82 & Wind > 6.9 & Temp <= 77" 
    ##                                      6                                      8 
    ##  "Temp <= 82 & Wind > 6.9 & Temp > 77"             "Temp > 82 & Wind <= 10.3" 
    ##                                      9 
    ##              "Temp > 82 & Wind > 10.3" 
    
    0 讨论(0)
提交回复
热议问题