# Feature Reduction with Random Forest

I am working with 46 variables ( remote sensing time series data - 8 days composite ) and around 466 samples, and using it to perform classification into 4 classes (1, 2, 3, 4). I want to reduce these features to most important 10-20

I was assuming that I would consider those features with highest MeanDecreaseGini and select top 10 or top 15 variables for further classification. But going through some posts in this forum, it looks like this might not be a correct interpretation.

Could you help me with how to perform this reduction programetically?

library(randomForest)
library(xlsx)
library(gdata)
setwd("E:/Working_Folder/R/Random_Forest/Test_Data")
all <- read.xls("Training_data_2015.xlsx", sheet = "NDVI_2015_all", perl="C:/Strawberry/perl/bin/perl.exe")


# Create a sample index of the total data set and divide it to train and test set

sample_index <- sample(466,300)
rf_train <- all[sample_index,]


# When the class column is numeric, Convert the class column to factor so that the random forest performs classification rather than regression and convert the training data into data frame

rf_train[,"Species"] <- factor(rf_train[,ncol(rf_train)])
rf_train <- as.data.frame(rf_train)
rf_test <- all[-sample_index,]
rf_model <- randomForest(Species~.,rf_train, importance=TRUE, ntree=500)
predict <- predict(rf_model,all)
all$predicted <- predict  # Check accuracey table(all$Species,predict)
mean(all\$Species==predict)
rf_model
importance(rf_model)