简体   繁体   中英

Getting "Variable Importance" from rpart

I'm performing a tree analysis using rpart, and I need to access the values of "Variable importance" as shown when the rpart object is printed.

Is there a way to do that?

Thanks!

@rawr indicated it in the comments, I'll just make it an answer:

You can extract the variable importance from a rpart object using:

fit$variable.importance

Just adding details on @user7779's answer, you can also access the information you need in the following way:

library(rpart)
my.tree = rpart(y ~ X, data = dta, method = "anova) # I am assuming regression tree.
summary(my.tree)

In the output, among the first lines, you find variable importance. Notice though that here everything is rescaled, thus you will get the relative importance (ie, numbers are going to sum up to one).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM