Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. # tree = 10000
  2. oob.err14 = numeric(10)
  3. for (mtry in 1:10) {
  4. fit14 = randomForest(lable ~ .-user_id -product_id, data = train_2, mtry = mtry, ntree = 10000)
  5. oob.err14[mtry] = fit14$err.rate[500]
  6. cat('We are performing iteration', mtry, '\n')
  7. }
  8.  
  9. plot(1:10, oob.err14[1:10], pch = 16, type = 'b',
  10. xlab = 'Variance Cosidered at Each Split',
  11. ylab = 'OOB Mean Squared Error',
  12. main = '4_Random Forest OOB Error Rates\nby # of Variables')
  13. # variance important:
  14. varImpPlot(fit14)
  15. which(oob.err14 == min(oob.err14))
  16. oob.err14[10]
  17.  
  18. ##### best model ######
  19. # mtry = 3
  20. fitt0 <- randomForest(lable ~ .-user_id -product_id, data = train_2, mtry = 3, ntree = 10000)
  21. fitt0
  22. varImpPlot(fitt0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement