I'm having trouble understanding how the varImp function works for a randomForest model with the caret package. In the example below feature var3 gets zero importance using caret's varImp function, but the underlying randomForest final model has non-zero importance for feature var3. Why is this the case?


rf <- train(x, y, 
      method = "rf",
      trControl = trainControl(method = "oob"),
      importance = TRUE,
      verbose = TRUE,
      tuneGrid = data.frame(mtry = num.predictors) )

fm <- rf$finalModel

> varImp(f)
rf variable importance

var1    100.00
var2    80.14
var3    0.00

> importance(fm)
        %IncMSE IncNodePurity
var2    872.7935      40505276
var1    1021.4707      55682866
var3     273.0168       3078731

2 Answers 2


As I understood you have only 3 variables. By default varImp function returns scaled results in range 0-100. Var3 has the lowest importance value and its scaled importance is zero. Try to call varImp(rf, scale = FALSE).

  • $\begingroup$ For illustration, the variable importance score for var2 was calculated by (873-273)/(1021-273) = 80. because the lowest %IncMSE value (var3 score = 273) must be subtracted from all other scores. $\endgroup$
    – Agile Bean
    Apr 2, 2021 at 1:10

Adding to @DrDom's answer, in order to provide further intuition:

The importance scores that varImp(rf, scale = FALSE) gives, is simply calculated by the following: rf$finalModel$importance[,1]/rf$finalModel$importanceSD

This is the feature's mean %IncMSE divided by its standard deviation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.