0

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

MLavoie
  • 9,671
  • 41
  • 36
  • 56
  • This was answered by [A previous post](http://stackoverflow.com/questions/2547402/is-there-a-built-in-function-for-finding-the-mode) – G5W Dec 10 '16 at 13:19
  • please invest some times and put your code in the correct format of coding of Stackoverflow! – Amir Koklan Dec 10 '16 at 14:01

0 Answers0