Skip to content

Instantly share code, notes, and snippets.

@apapiu
Last active April 29, 2016 23:01
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 apapiu/a0aabb27b85cb954843d24dfaac2f7d5 to your computer and use it in GitHub Desktop.
Save apapiu/a0aabb27b85cb954843d24dfaac2f7d5 to your computer and use it in GitHub Desktop.
Random Forest of Xgboosts
# X is the training matrix, y are the labels.
library(xgboost)
n = 100
nrows = dim(X)[1]
nfeats = dim(X)[2]
replicate(n, {
boot_sample <- sample(1:nrows, replace = TRUE)
features_selected <- sample(1:nfeats, sqrt(nfeats)) #seems to work better for bagging
model_xgb <- xgboost(data = X[boot_sample, features_selected], label = y[boot_sample]) #choose your params here.
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment