mlr-org / mlr

Machine Learning in R
https://mlr.mlr-org.com
Other
1.63k stars 402 forks source link

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

Closed jeonghyunwoo closed 7 years ago

jeonghyunwoo commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Thank you a lot. I missunderstood that "par.vals" can only have scalar arguments.

jakob-r commented 7 years ago

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
jeonghyunwoo commented 7 years ago

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 https://github.com/mlr-org/mlr/issues/1305#issuecomment-256301109, or mute the thread https://github.com/notifications/unsubscribe-auth/AQDKZdPSD9ut2QC3Ld1BlIZnDWO_z4clks5q3yLLgaJpZM4Kfsz3 .