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?
require(randomForest)
require(caret)
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
Overall
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