# \donttest{
# load packages and data
library(h2o)
library(DALEXtra)
# data <- DALEX::titanic_imputed
# init h2o
cluster <- try(h2o::h2o.init())
if (!inherits(cluster, "try-error")) {
# stop h2o progress printing
h2o.no_progress()
# split the data
# h2o_split <- h2o.splitFrame(as.h2o(data))
# train <- h2o_split[[1]]
# test <- as.data.frame(h2o_split[[2]])
# h2o automl takes target as factor
# train$survived <- as.factor(train$survived)
# fit a model
# automl <- h2o.automl(y = "survived",
# training_frame = train,
# max_runtime_secs = 30)
# create an explainer for the model
# explainer <- explain_h2o(automl,
# data = test,
# y = test$survived,
# label = "h2o")
titanic_test <- read.csv(system.file("extdata", "titanic_test.csv", package = "DALEXtra"))
titanic_train <- read.csv(system.file("extdata", "titanic_train.csv", package = "DALEXtra"))
titanic_h2o <- h2o::as.h2o(titanic_train)
titanic_h2o["survived"] <- h2o::as.factor(titanic_h2o["survived"])
titanic_test_h2o <- h2o::as.h2o(titanic_test)
model <- h2o::h2o.gbm(
training_frame = titanic_h2o,
y = "survived",
distribution = "bernoulli",
ntrees = 500,
max_depth = 4,
min_rows = 12,
learn_rate = 0.001
)
explain_h2o(model, titanic_test[,1:17], titanic_test[,18])
try(h2o.shutdown(prompt = FALSE))
}
# }
Run the code above in your browser using DataLab