Roberto
Roberto

Reputation: 96

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!

Upvotes: 3

Views: 4492

Answers (2)

riccardo-df
riccardo-df

Reputation: 552

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 (i.e., numbers are going to sum up to one hundred).

Upvotes: 0

user7779
user7779

Reputation: 115

@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

Upvotes: 6

Related Questions