In random forest, you can calculate important variables with IMPORTANCE= TRUE parameter.
library(caret)
rfTune <- train(dev[, -1], dev[,1], method = "rf", ntree = 100, importance = TRUE)
MeanDecreaseAccuracy table represents how much removing each variable reduces the accuracy of the model.
Selecting top 10 variables
ImportanceOrder <- order(rfTune$finalModel$importance[,1],decreasing = TRUE)
top10 <- rownames(rfTune$finalModel$importance[ImportanceOrder,])[1:10]
subsetimp <- subset(training, select = top10)
Post a Comment