I have a dataset with 5 independent variables and a categorical dependent variable.
I would like to develop a code in R that allows me to predict the final results for a test data set.
I would like to implement bagging using as classifier a decision tree. In order to obtain the final predictions I would like to use the uniform voting procedure.
The code that I developed is the following
set.seed(10)
all_data<-qwe
positions <- sample(nrow(all_data),size=floor((nrow(all_data)/5)*4))
training<- all_data[positions,]
testing<- all_data[-positions,]
n <-10
for (i in 1:n ){
training_positions <- sample(nrow(training), size=floor((nrow(training)/3)))
train_pos<-1:nrow(training) %in% training_positions
model_tree <- rpart(UNS~., data=training[train_pos,])
pred <- predict(model_tree, newdata = testing, type="class")
print(as.matrix(pred))
plot(pred)
text(pred)
}
I have the predictions made by each decision tree (10 decision trees), but I do not know how to determine the most common prediction for each observation ( I mean the mode).
Any help would be welcome!
Thanks in advance!
Best regards,
Liza Vieira