From f119907c3134aae1dc16da4c8e8b6f6dc851f6cc Mon Sep 17 00:00:00 2001 From: Minh Le Date: Tue, 9 May 2017 16:55:51 +0200 Subject: [PATCH] create a thesthtat for h2oautoencoder, analogous to h2ogbm. BUT: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In test_that - “oneclass_h2oautoencoder”, reproducible = TRUE and seed= 1234 need to be set in parset.list before the for-block, instead of setting them in the for-block like in h2ogmb, otherwise testProbParsets return error because of different prediction values. In test_that-(“class names are integers and probabilities predicted (#1787)" activation function needs to be set to “Tanh” instead of the default “Rectifire”, otherwise resample() return an error: Error: DistributedException from localhost/127.0.0.1:54321, caused by java.lang.UnsupportedOperationException: (This error occurs very often when using h2o, there are no clear and not a lot explanation in the web how to solve it or why it happens, but it seems like to be related with the case if the model is “unstable”. The activation function “tanh” has a natural bound and suitable to “control” the instability. --- tests/testthat/test_oneclass_h2oautoencoder.R | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/testthat/test_oneclass_h2oautoencoder.R diff --git a/tests/testthat/test_oneclass_h2oautoencoder.R b/tests/testthat/test_oneclass_h2oautoencoder.R new file mode 100644 index 0000000000..895c1ce2c5 --- /dev/null +++ b/tests/testthat/test_oneclass_h2oautoencoder.R @@ -0,0 +1,44 @@ +context("oneclass_h2oautoencoder") + +test_that("oneclass_h2oautoencoder", { + skip_on_travis() + requirePackages("h2o", default.method = "load") + h2o::h2o.init() + + parset.list = list( + list(), + list(activation = "Tanh"), + list(l1 = 1), + list(hidden = c(5,2,5)) + ) + + parset.list = lapply(parset.list, function(x) c(x, reproducible = TRUE, seed = 1234)) + old.probs.list = list() + + train.hex = h2o::as.h2o(oneclass.train[, -oneclass.col], destination_frame = "train.hex") + test.hex = h2o::as.h2o(oneclass.test[, -oneclass.col], destination_frame = "test.hex") + + for (i in seq_along(parset.list)) { + parset = parset.list[[i]] + parset = c(parset, list(x = colnames(train.hex), training_frame = train.hex, + autoencoder = TRUE)) + #set.seed(getOption("mlr.debug.seed")) + m = do.call(h2o.deeplearning, parset) + p = h2o.anomaly(m, test.hex, per_feature=FALSE) + old.probs.list[[i]] = as.vector(p) + } + + testProbParsets("oneclass.h2o.autoencoder", oneclass.df[, -oneclass.col], + oneclass.target, oneclass.train.inds, old.probs.list, parset.list) +}) + +test_that("class names are integers and probabilities predicted (#1787)", { + df = data.frame(matrix(runif(100, 0, 1), 100, 9)) + + oneclass.task = makeOneClassTask(id = "example", data = df) + ae.lrn = makeLearner("oneclass.h2o.autoencoder", predict.type = "prob", activation = "Tanh") + rdesc = makeResampleDesc("CV", iters = 2L) + rin = makeResampleInstance(rdesc, task = oneclass.task) + r = resample(ae.lrn, oneclass.task, rin) + expect_false(is.null(r$pred)) +})