importance.Rd
This is the extractor function for variable importance measures as
produced by randomForest
.
# S3 method for randomForest importance(x, type=NULL, class=NULL, scale=TRUE, ...)
x | an object of class |
---|---|
type | either 1 or 2, specifying the type of importance measure (1=mean decrease in accuracy, 2=mean decrease in node impurity). |
class | for classification problem, which class-specific measure to return. |
scale | For permutation based measures, should the measures be divided their ``standard errors''? |
... | not used. |
A matrix of importance measure, one row for each predictor variable. The column(s) are different importance measures.
Here are the definitions of the variable importance measures. The first measure is computed from permuting OOB data: For each tree, the prediction error on the out-of-bag portion of the data is recorded (error rate for classification, MSE for regression). Then the same is done after permuting each predictor variable. The difference between the two are then averaged over all trees, and normalized by the standard deviation of the differences. If the standard deviation of the differences is equal to 0 for a variable, the division is not done (but the average is almost always equal to 0 in that case).
The second measure is the total decrease in node impurities from splitting on the variable, averaged over all trees. For classification, the node impurity is measured by the Gini index. For regression, it is measured by residual sum of squares.
set.seed(4543) data(mtcars) mtcars.rf <- randomForest(mpg ~ ., data=mtcars, ntree=1000, keep.forest=FALSE, importance=TRUE) importance(mtcars.rf)#> %IncMSE IncNodePurity #> cyl 16.472330 171.12561 #> disp 20.315899 267.58864 #> hp 17.448036 188.63849 #> drat 7.420288 63.36480 #> wt 17.760581 241.42823 #> qsec 2.865722 29.11372 #> vs 5.222745 25.27230 #> am 4.441045 21.38283 #> gear 4.454561 15.27576 #> carb 8.133980 31.60571importance(mtcars.rf, type=1)#> %IncMSE #> cyl 16.472330 #> disp 20.315899 #> hp 17.448036 #> drat 7.420288 #> wt 17.760581 #> qsec 2.865722 #> vs 5.222745 #> am 4.441045 #> gear 4.454561 #> carb 8.133980