4. Task 4

4.1. Task 4.1: Decision Trees

DocumentationrandomForest function - RDocumentation


Action:
ação ícone

Expected:
resultado ícone

> install.packages('randomForest')
> library('randomForest')

 

Instalation of a package is easy, just select a mirror close to you, and wait. 

Action:
ação ícone

Expected:
resultado ícone

> # ensure that the data is discrete (c.c. are considered linear) > for(i in 2:6) data[,i]<-factor(data[,i]) > test <- randomForest(x=data[,2:5], y=data[,6], ntree=1, importance=TRUE) > print(test) > getTree(test, 1) # shows tree information, must be drawn > test$type # confirm that it was a classification and not a regression > predict(test, data[,2:5]) 


 

The method was called with a single decision tree. We can see in the confusion matrix, and error rate estimation on 33%. We can get the decision tree, one line for each node, with left/right doughter, or 0 if is a final node, and in that case a prediction will exist. We can also use predict, to predict a specific set of data, in this case we use the same data for trainning, and get for each case, the predict values. 

Action: repeat with training and test sets