简体   繁体   English

从 rpart 获取“变量重要性”

[英]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.我正在使用 rpart 执行树分析,我需要访问“变量重要性”的值,如打印 rpart 对象时所示。

Is there a way to do that?有没有办法做到这一点?

Thanks!谢谢!

@rawr indicated it in the comments, I'll just make it an answer: @rawr 在评论中指出了这一点,我只是把它作为一个答案:

You can extract the variable importance from a rpart object using:您可以使用以下方法从 rpart 对象中提取变量重要性:

fit$variable.importance

Just adding details on @user7779's answer, you can also access the information you need in the following way:只需在@user7779 的答案中添加详细信息,您还可以通过以下方式访问您需要的信息:

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).请注意,这里的所有内容都重新调整了比例,因此您将获得相对重要性(即,数字总和为 1)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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