Skip to content

Instantly share code, notes, and snippets.

@BenHeubl
Created February 13, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenHeubl/7dc11574812c895e9e6cbddbfaf0f88b to your computer and use it in GitHub Desktop.
Save BenHeubl/7dc11574812c895e9e6cbddbfaf0f88b to your computer and use it in GitHub Desktop.
tut18
# Using For loop to identify the right mtry for model (this took around 4 minutes for me. Get yourself a drink :-)
accuracy_list =c()
for (i in 3:8) {
print(i)
model_optimal <- randomForest(INCOME ~ ., data = TrainSet, ntree = 500, mtry = i, importance = TRUE)
predValid <- predict(model_optimal, ValidSet, type = "class")
accuracy_list[i-2] = mean(predValid == ValidSet$INCOME)
}
accuracy_list
#[Output]:
#[1] 0.6333333 0.6408333 0.6425000 0.6454167 0.6450000
#[6] 0.6454167
#We can also plot the result:
plot(3:8,accuracy_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment