forked from h2oai/h2o-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.R
More file actions
40 lines (32 loc) · 1.24 KB
/
example.R
File metadata and controls
40 lines (32 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#
# Example R code for generating an H2O Scoring POJO.
#
# "Safe" system. Error checks process exit status code. stop() if it failed.
safeSystem <- function(x) {
print(sprintf("+ CMD: %s", x))
res <- system(x)
print(res)
if (res != 0) {
msg <- sprintf("SYSTEM COMMAND FAILED (exit status %d)", res)
stop(msg)
}
}
library(h2o)
cat("Starting H2O\n")
myIP <- "localhost"
myPort <- 54321
h <- h2o.init(ip = myIP, port = myPort, startH2O = TRUE)
cat("Building GBM model\n")
df <- h2o.importFile(path = normalizePath("./training_data.csv"));
y <- "Label"
x <- c("Has4Legs","CoatColor","HairLength","TailLength","EnjoysPlay","StaresOutWindow","HoursSpentNapping","RespondsToCommands","EasilyFrightened","Age", "Noise1", "Noise2", "Noise3", "Noise4", "Noise5")
gbm.h2o.fit <- h2o.gbm(training_frame = df, y = y, x = x, model_id = "GBMPojo", ntrees = 10)
cat("Downloading Java prediction model code from H2O\n")
model_id <- gbm.h2o.fit@model_id
tmpdir_name <- "generated_model"
cmd <- sprintf("rm -fr %s", tmpdir_name)
safeSystem(cmd)
cmd <- sprintf("mkdir %s", tmpdir_name)
safeSystem(cmd)
h2o.download_pojo(gbm.h2o.fit, "./generated_model/")
cat("Note: H2O will shut down automatically if it was started by this R script and the script exits\n")