Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ Config/testthat/edition: 3
Config/testthat/parallel: false
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.0.9000
RoxygenNote: 7.2.1
VignetteBuilder: knitr
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export(extract_fit_engine)
export(extract_fit_parsnip)
export(get_leaderboard)
export(h2o_activation)
export(h2o_end)
export(h2o_get_frame)
export(h2o_get_model)
export(h2o_predict)
Expand Down
16 changes: 16 additions & 0 deletions R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' h2o_start()
#' }
#' @rdname h2o-server
#' @keywords internal
#' @export
h2o_start <- function() {
res <- utils::capture.output(h2o:::with_no_h2o_progress(
Expand All @@ -16,6 +17,16 @@ h2o_start <- function() {
}

#' @rdname h2o-server
#' @keywords internal
#' @export
h2o_end <- function() {
if (h2o_running()) {
h2o::h2o.shutdown(prompt = FALSE)
}
}

#' @rdname h2o-server
#' @keywords internal
#' @export
h2o_running <- function(verbose = FALSE) {
res <- try(h2o::h2o.clusterIsUp(), silent = TRUE)
Expand All @@ -30,18 +41,21 @@ h2o_running <- function(verbose = FALSE) {
}

#' @rdname h2o-server
#' @keywords internal
#' @export
h2o_remove <- function(id) {
h2o::h2o.rm(id)
}

#' @rdname h2o-server
#' @keywords internal
#' @export
h2o_remove_all <- function() {
h2o::h2o.removeAll()
}

#' @rdname h2o-server
#' @keywords internal
#' @export
h2o_get_model <- function(id) {
res <- eval_silently(h2o:::with_no_h2o_progress(h2o::h2o.getModel(id)))
Expand All @@ -52,6 +66,7 @@ h2o_get_model <- function(id) {
}

#' @rdname h2o-server
#' @keywords internal
#' @export
h2o_get_frame <- function(id) {
res <- eval_silently(h2o:::with_no_h2o_progress(h2o::h2o.getFrame(id)))
Expand All @@ -61,6 +76,7 @@ h2o_get_frame <- function(id) {
}

#' @rdname h2o-server
#' @keywords internal
#' @export
h2o_xgboost_available <- function() {
"XGBoost" %in% h2o::h2o.list_core_extensions()
Expand Down
4 changes: 4 additions & 0 deletions man/h2o-server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
library(testthat)
library(agua)

# Working on figuring out an issue where the first test runs but others fail with
# Unexpected CURL error: Failed to connect to localhost port 54321 after 1 ms: Connection refused
# [1] "Job request failed Unexpected CURL error: Failed to connect to localhost port 54321 after 1 ms: Connection refused, will retry after 3s."
agua::h2o_start()
test_check("agua")
h2o::h2o.shutdown(prompt = FALSE)
88 changes: 88 additions & 0 deletions tests/testthat/_snaps/tune_grid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# tune model only (with id)

Code
res
Output
# Tuning results
# 5-fold cross-validation
# A tibble: 5 x 5
splits id .metrics .notes .predictions
<list> <chr> <list> <list> <list>
1 <split [632/159]> Fold1 <NULL> <tibble [1 x 3]> <NULL>
2 <split [633/158]> Fold2 <NULL> <tibble [1 x 3]> <NULL>
3 <split [633/158]> Fold3 <NULL> <tibble [1 x 3]> <NULL>
4 <split [633/158]> Fold4 <NULL> <tibble [1 x 3]> <NULL>
5 <split [633/158]> Fold5 <NULL> <tibble [1 x 3]> <NULL>

There were issues with some computations:

- Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u...

Run `show_notes(.Last.tune.result)` for more information.

# tune model only (without id)

Code
res
Output
# Tuning results
# 5-fold cross-validation
# A tibble: 5 x 5
splits id .metrics .notes .predictions
<list> <chr> <list> <list> <list>
1 <split [632/159]> Fold1 <NULL> <tibble [1 x 3]> <NULL>
2 <split [633/158]> Fold2 <NULL> <tibble [1 x 3]> <NULL>
3 <split [633/158]> Fold3 <NULL> <tibble [1 x 3]> <NULL>
4 <split [633/158]> Fold4 <NULL> <tibble [1 x 3]> <NULL>
5 <split [633/158]> Fold5 <NULL> <tibble [1 x 3]> <NULL>

There were issues with some computations:

- Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u...

Run `show_notes(.Last.tune.result)` for more information.

# tune model only (with id and recipe)

Code
res
Output
# Tuning results
# 5-fold cross-validation
# A tibble: 5 x 5
splits id .metrics .notes .predictions
<list> <chr> <list> <list> <list>
1 <split [632/159]> Fold1 <NULL> <tibble [1 x 3]> <NULL>
2 <split [633/158]> Fold2 <NULL> <tibble [1 x 3]> <NULL>
3 <split [633/158]> Fold3 <NULL> <tibble [1 x 3]> <NULL>
4 <split [633/158]> Fold4 <NULL> <tibble [1 x 3]> <NULL>
5 <split [633/158]> Fold5 <NULL> <tibble [1 x 3]> <NULL>

There were issues with some computations:

- Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u...

Run `show_notes(.Last.tune.result)` for more information.

# tune model and recipe

Code
res
Output
# Tuning results
# 5-fold cross-validation
# A tibble: 5 x 5
splits id .metrics .notes .predictions
<list> <chr> <list> <list> <list>
1 <split [632/159]> Fold1 <NULL> <tibble [1 x 3]> <NULL>
2 <split [633/158]> Fold2 <NULL> <tibble [1 x 3]> <NULL>
3 <split [633/158]> Fold3 <NULL> <tibble [1 x 3]> <NULL>
4 <split [633/158]> Fold4 <NULL> <tibble [1 x 3]> <NULL>
5 <split [633/158]> Fold5 <NULL> <tibble [1 x 3]> <NULL>

There were issues with some computations:

- Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u... - Error(s) x1: Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, u...

Run `show_notes(.Last.tune.result)` for more information.

14 changes: 7 additions & 7 deletions tests/testthat/test-case-weights.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
options("prefer_RCurl" = FALSE)
h2o_start()

test_that("case weights works", {
skip_if(!interactive())
skip_if_not_installed("modeldata")

h2o_start()
data("two_class_dat", package = "modeldata")

wts <- runif(nrow(two_class_dat))
Expand All @@ -18,10 +18,10 @@ test_that("case weights works", {
set.seed(1)
fit_res <- spec %>%
fit(Class ~ ., data = two_class_dat, case_weights = wts)
wf_res <- workflow() %>%
add_model(spec) %>%
add_formula(Class ~ .) %>%
add_case_weights(wts) %>%
wf_res <- workflows::workflow() %>%
workflows::add_model(spec) %>%
workflows::add_formula(Class ~ .) %>%
workflows::add_case_weights(wts) %>%
fit(data = two_class_dat %>% dplyr::mutate(wts = wts))


Expand Down
17 changes: 3 additions & 14 deletions tests/testthat/test-misc.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
test_that("data conversion", {
skip_if(!interactive())
h2o_start()
options("prefer_RCurl" = FALSE)
h2o_start()

test_that("data conversion", {
expect_silent(cars_1 <- as_h2o(mtcars))
expect_equal(class(cars_1$data), "H2OFrame")
expect_equal(class(cars_1$id), "character")
expect_equal(as_tibble(cars_1$data), tibble::as_tibble(mtcars))
})


test_that("server functions", {
# skip("h2o server issues with testthat")
skip_if(!interactive())

expect_silent(agua::h2o_start())
expect_true(h2o_running())
h2o::h2o.shutdown(prompt = FALSE)
expect_false(h2o_running())
})
37 changes: 3 additions & 34 deletions tests/testthat/test-parsnip-execution.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("random forest execution", {
skip_if(!interactive())
h2o_start()
options("prefer_RCurl" = FALSE)
h2o_start()

test_that("random forest execution", {
expect_h2o_fit(rand_forest(mtry = 2, trees = 5) %>%
set_mode("regression"))

Expand All @@ -11,70 +11,46 @@ test_that("random forest execution", {


test_that("linear regression execution", {
skip_if(!interactive())
h2o_start()

expect_h2o_fit(linear_reg(penalty = 0.1))
})

test_that("logistic regression execution", {
skip_if(!interactive())
h2o_start()

expect_h2o_fit(logistic_reg(mixture = 1))
})

test_that("poisson regression execution", {
skip_if(!interactive())
h2o_start()

expect_h2o_fit(poisson_reg(engine = "h2o"),
data = as.data.frame(Titanic),
formula = Freq ~ .
)
})

test_that("multinomial regression execution", {
skip_if(!interactive())
h2o_start()

expect_h2o_fit(multinom_reg(),
data = iris,
formula = Species ~ .
)
})

test_that("naive bayes execution", {
skip_if(!interactive())
h2o_start()

expect_h2o_fit(naive_Bayes(engine = "h2o", Laplace = 1))
})

test_that("mlp execution", {
skip_if(!interactive())
h2o_start()

expect_h2o_fit(mlp(hidden_units = 100) %>%
set_mode("regression"))
expect_h2o_fit(mlp(hidden_units = 100) %>%
set_mode("classification"))
})

test_that("rule fit execution", {
skip_if(!interactive())
h2o_start()

expect_h2o_fit(rule_fit(engine = "h2o", trees = 10, tree_depth = 3) %>%
set_mode("regression"))
expect_h2o_fit(rule_fit(engine = "h2o", trees = 10, tree_depth = 3) %>%
set_mode("classification"))
})

test_that("xgboost execution", {
skip_if(!interactive())
h2o_start()

skip_if(!h2o_xgboost_available())
expect_h2o_fit(boost_tree(learn_rate = .1, trees = 5) %>%
set_mode("regression"))
Expand All @@ -83,18 +59,13 @@ test_that("xgboost execution", {
})

test_that("gbm execution", {
skip_if(!interactive())
h2o_start()

expect_h2o_fit(boost_tree(learn_rate = .1, trees = 5) %>%
set_mode("regression"), engine = "h2o_gbm")
expect_h2o_fit(boost_tree(learn_rate = .1, trees = 5) %>%
set_mode("classification"), engine = "h2o_gbm")
})

test_that("automl execution", {
skip_if(!interactive())
h2o_start()

data(two_class_dat, package = "modeldata")
set.seed(1)
Expand All @@ -116,8 +87,6 @@ test_that("automl execution", {
})

test_that("automl tools", {
skip_if(!interactive())
h2o_start()
set.seed(1)

spec <- auto_ml() %>%
Expand Down
Loading