Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify 'hidden' parameter in grid search of 'classif.h2o.deeplearning'? #1305

Closed
jeonghyunwoo opened this issue Oct 25, 2016 · 5 comments

Comments

@jeonghyunwoo
Copy link

jeonghyunwoo commented Oct 25, 2016

In h2o package, I can specify hyper parameters as belows:

hyperparm <-list( hidden = list ( c(10,10), c(20,20,20), c(30,30,30) )

mlr seems to support this usage with 'makeDiscreteVectorParam'.
Below is an usage of the function :

makeDiscreteVectorParam(id, len, values, default, requires = NULL,  tunable = TRUE)

How I can put 'hidden = list( c(10,10), c(20,20,20), c(30,30,30))' into 'makeDiscreteVectorParm' ?

@ja-thomas
Copy link
Contributor

ja-thomas commented Oct 25, 2016

Hi,

in mlr you can set the hyper parameter of a learning like that

lrn = makeLearner("classif.h2o.deeplearning", par.vals = list(hidden = c(30, 30)))

For a list of available parameters of a learner you can use getParamSet(lrn).

All of this is explained in more details in the tutorial: http://mlr-org.github.io/mlr-tutorial/release/html/learner/index.html

I'm not sure how to set a list as the number of hidden nodes as you implied, could you provide a reproducable (minimal) example what you are trying to do?

EDIT: Ah, I just overread that you want to do a grid search
EDIT2: I'm not sure if we are able to tune over integer vectors of different lenghts

@larskotthoff
Copy link
Sponsor Member

Unfortunately, we currently don't support this. We require parameters to have a certain type and supporting parameters that can have several types is tricky.

You could just redeclare the learner with hidden as an untyped parameter as a hack to make it work though.

@jeonghyunwoo
Copy link
Author

jeonghyunwoo commented Oct 25, 2016 via email

@jakob-r
Copy link
Sponsor Member

jakob-r commented Oct 26, 2016

You probably refer to h2o.grid( algorithm="deeplearning", ...) http://learn.h2o.ai/content/tutorials/deeplearning/#hyper-parameter-tuning-with-grid-search because it seems to me that in the newest version of h2o hidden actually has to be an integer vector and not a list.

If you had still the version where you can really pass a list it would look something like that

lrn$par.set$pars$hidden = makeUntypedLearnerParam(id = "hidden")
lrn = setHyperPars(lrn, par.vals = list(hidden = list(c(10,10), c(20,20,20), c(30,30,30))))

Otherwise a bit tideous but most flexible:

library(mlr)
lrn = makeLearner("classif.h2o.deeplearning")
hyperparm = list(c(10,10), c(20,20,20), c(30,30,30))
lrns = lapply(hyperparm, function(x) {
  lrn2 = setHyperPars(lrn, par.vals = list(hidden = x))
  lrn2$id = paste0(lrn$id,":",paste0(x, collapse = "."))
  return(lrn2)
})
bmrs = benchmark(learners = lrns, tasks = iris.task)

Another may be more elegant approach:

ps = makeParamSet(
  makeDiscreteParam(id = "hidden", values = list(a = c(10,10), b = c(20,20,20), c = c(30,30,30)))
)
lrn = makeLearner("classif.h2o.deeplearning")
des = generateGridDesign(ps)
tune.res = tuneParams(learner = lrn, task = iris.task, resampling = makeResampleDesc("Holdout"), measures = acc, control = makeTuneControlDesign(design = des), par.set = ps)
tune.res

@jakob-r jakob-r closed this as completed Oct 26, 2016
@jeonghyunwoo
Copy link
Author

I appreciate you for detailed examples.
It helped me so much.

      1. 오후 6:52에 "Jakob Richter" notifications@github.com님이 작성:

You probably refer to h2o.grid(
algorithm="deeplearning", ...) http://learn.h2o.ai/content/
tutorials/deeplearning/#hyper-parameter-tuning-with-grid-search because
it seems to me that in the newest version of h2o hidden actually has to
be an integer vector and not a list.

If you had still the version where you can really pass a list it would
look something like that

lrn$par.set$pars$hidden = makeUntypedLearnerParam(id = "hidden")lrn = setHyperPars(lrn, par.vals = list(hidden = list(c(10,10), c(20,20,20), c(30,30,30))))

Otherwise a bit tideous but most flexible:

library(mlr)lrn = makeLearner("classif.h2o.deeplearning")hyperparm = list(c(10,10), c(20,20,20), c(30,30,30))lrns = lapply(hyperparm, function(x) {
lrn2 = setHyperPars(lrn, par.vals = list(hidden = x))
lrn2$id = paste0(lrn$id,":",paste0(x, collapse = "."))
return(lrn2)
})bmrs = benchmark(learners = lrns, tasks = iris.task)

Another may be more elegant approach:

ps = makeParamSet(
makeDiscreteParam(id = "hidden", values = list(a = c(10,10), b = c(20,20,20), c = c(30,30,30)))
)lrn = makeLearner("classif.h2o.deeplearning")des = generateGridDesign(ps)tune.res = tuneParams(learner = lrn, task = iris.task, resampling = makeResampleDesc("Holdout"), measures = acc, control = makeTuneControlDesign(design = des), par.set = ps)tune.res


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#1305 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AQDKZdPSD9ut2QC3Ld1BlIZnDWO_z4clks5q3yLLgaJpZM4Kfsz3
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants