简体   繁体   中英

randomForest::importance() : type=2 is working, but not type=1

I'm using randomForest package. In order to get variable importances, I'm using importance() function. I want to change the type of importance measure. It's determined by "type" argument, which have 2 possible values : type=1 or type=2. Here is an example :

library(randomForest)

Y = runif(100, 0.0, 1.0)
X1 = runif(100, 0.0, 1.0)
X2 = runif(100, 0.0, 1.0)

rf.model = randomForest::randomForest(Y~X1+X2)

# type 2 : mean decrease in node impurity
imp2 = randomForest::importance(x=rf.model,type=2)

# type 1 : mean decrease in accuracy
imp1 = randomForest::importance(x=rf.model,type=1)

imp2 output :

      IncNodePurity
X1      3.130248
X2      3.023091

imp1 output :

X1
X2

As you can see, type=2 (mean decrease in node impurity) is working, but not type=1 (mean decrease in accuracy). Do you know how to solve this problem ?

You have to enable it in your model first

rf.model = randomForest::randomForest(Y~X1+X2,importance=T)

then it will work.

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