getwd()
sessionInfo()
#*******************************************************************************
# Lista de paquetes y funciones a instalar
.packages = c(
  "mlbench",                # leer raster
  "caret" ,                   # leer raster
  "e1071",
  "randomForest"
)
# Si no estan instalados los paquetes, instalar automaticamente
.inst <- .packages %in% installed.packages()
if(length(.packages[!.inst]) > 0) install.packages(.packages[!.inst])
.libPaths()    # chek libraries

# Si no estan cargados los paquetes, cargar paquetes y funciones
lapply(.packages, require, character.only=TRUE)

# Use RFE and to select features


# load the data
data(Sonar)
datos <- Sonar
# define the control using a random forest selection function
control <- rfeControl(functions=rfFuncs, method="cv", number=10)
# run the RFE algorithm
x <- Sonar[,1:60]
y <- Sonar[,61]
sizes <- c(10,20,30,40,50,60)
results <- rfe(x, y, sizes=sizes, rfeControl=control)
# summarize the results
print(results)
# list the chosen features
predictors(results)
# plot accuracy versus the number of features
plot(results, type=c("g", "o"))
