Skip to content

Instantly share code, notes, and snippets.

@ledell
Created April 3, 2017 05:13
Show Gist options
  • Save ledell/5223980f9cfe3cf170648c3ff2748486 to your computer and use it in GitHub Desktop.
Save ledell/5223980f9cfe3cf170648c3ff2748486 to your computer and use it in GitHub Desktop.
library(h2o)
h2o.init(nthreads = -1)
# Import a sample binary outcome train/test set into R
train <- h2o.importFile("https://s3.amazonaws.com/erin-data/higgs/higgs_train_5k.csv")
test <- h2o.importFile("https://s3.amazonaws.com/erin-data/higgs/higgs_test_5k.csv")
y <- "response"
x <- setdiff(names(train), y)
#For binary classification, response should be a factor
train[,y] <- as.factor(train[,y])
test[,y] <- as.factor(test[,y])
modelname <- 'gbm_34325f.hex'
h2o.gbm(x = x, y = y, training_frame = train,
validation_frame = test, distribution="bernoulli",
ntrees = 6000, learn_rate = 0.01, max_depth = 5,
min_rows = 40, model_id = modelname)
gbm <- h2o.getModel(modelname)
h2o.saveModel(gbm, path='.', force = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment