I am trying to build a training and test model from a data frame. I am using random forest method and building the model.
My data frame has 6 columns where the first column is the outcome (yes/no) and rest 5 columns are independent variables. I build the model using the all the independent variables (outcome ~ ., data =training, method="rf").
What I am trying to do is to try all the possible combinations of the independent variables and generate a model (like col1, col1 + col2, col1+col2+col3 and so on..) there will be 120 combinations possible with my data frame.
I need help to do this automatically in loop but am not able to figure out how I can put the loop together.
Thanks in advance.
data <- read.csv("temp.csv", header = TRUE)
splitdata <- createDataPartition(y=data$var1, p=0.75)
training <- df[splitdata,]
testing <- df[-splitdata,]
no_of_cols <- 2:ncol(training)
for (i in no_col)
{
permn (no_of_col)
#model <- train(var1 ~ ., data=training, method="rf")
model[i] <- train(var1 ~ training[,i], data=training, method="rf")
predictions[i] <- predict(model[i],newdata=testing)
}