R : Train Random Forest with Caret Package (R)

Live Online Training : Data Science with R

- Explain Advanced Algorithms in Simple English
- Live Projects
- Case Studies
- Job Placement Assistance
- Get 10% off till Sept 25, 2017
- Batch starts from October 8, 2017

Train Random Forest with Caret Package (R)

1. No Cross Validation / Bootstrapping
mtry <- tuneRF(dev[, -1], dev[,1], ntreeTry=500, stepFactor=1.5,improve=0.01, trace=TRUE, plot=TRUE)

best.m <- mtry[mtry[, 2] == min(mtry[, 2]), 1]

set.seed(825)
trained1 <- train(dev[, -1], dev[,1], method = "rf", ntree=100, tuneGrid=data.frame(mtry=best.m), trControl = trainControl(method = "none"), importance = TRUE)

2. Cross Validation with Manual Fine Tuning
sqtmtry<- round(sqrt(ncol(mydata) - 1))
rfGrid <- expand.grid(mtry = c(round(sqtmtry / 2), sqtmtry, 2 * sqtmtry))

ctrl <- trainControl(method = "cv", classProbs = TRUE, summaryFunction = twoClassSummary, number = 3)

set.seed(2)
trained2<- train(Y ~ . , data = mydata, method = "rf", ntree = 500, tuneGrid = rfGrid, metric = "ROC",
trControl = ctrl, importance = TRUE)
3. Cross Validation with Automatic Fine Tuning

set.seed(2)
trained3 <- train(Y ~ . , data = mydata, method = "rf", ntree = 500, tunelength = 10, metric = "ROC", trControl = ctrl, importance = TRUE)

4. Bootstrapping (Repetitive Sampling)

set.seed(2) tuned <- train(dev[, -1], dev[,1], method = "rf" , ntree =10)
Note : By default, it creates 25 repetitive samples.

If you want to set 10 repetitive samples.
tuned <- train(dev[, -1], dev[,1], method = "rf" , ntree =10 , trControl= trainControl(method="boot", number=10))



R Tutorials : 75 Free R Tutorials


Statistics Tutorials : 50 Statistics Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.


While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

0 Response to "R : Train Random Forest with Caret Package (R)"

Post a Comment

Next → ← Prev