STAT 897D
Published on STAT 897D (https://onlinecourses.science.psu.edu/stat857)

Home > GCD.5 - Random Forest

GCD.5 - Random Forest

Sample R code for
Random Forest.

Sample R code for Random Forest.

 

library(randomForest)
rf50 <- randomForest(Creditability ~., data = Train50, ntree=200, importance=T, proximity=T)
plot(rf50, main="")
rf50
Test50_rf_pred <- predict(rf50, Test50, type="class")
table(Test50_rf_pred, Test50$Creditability)
importance(rf50)
varImpPlot(rf50,  main="", cex=0.8)

Completely unsupervised random forest method on Training data with ntree = 200 leads to the following error plot:

error plot

Importance of predictors are given in the following dotplot.

dotplots of results

which gives rise to the following classification table:

table of results

With judicious choice of more important predictors, further improvement in accuracy is possible. But as improvement is slight, no attempt is made for supervised random forest.


Source URL: https://onlinecourses.science.psu.edu/stat857/node/220