Skip to content

Commit

Permalink
create a thesthtat for h2oautoencoder, analogous to h2ogbm. BUT:
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Minh Le committed May 9, 2017
1 parent 8da8556 commit f119907
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/testthat/test_oneclass_h2oautoencoder.R
Original file line number Diff line number Diff line change
@@ -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))
})

0 comments on commit f119907

Please sign in to comment.