2016-03-01 4 views
5

Sto creando utenti personalizzati, in particolare sto cercando di utilizzare gli algoritmi di apprendimento automatico h2o all'interno del framework mlr. Il parametro 'hidden' della funzione h2o.deeplearning, è un vettore intero che voglio sintonizzare. Ho definito il parametro 'nascosto' nel modo seguente:Vettore intero di sintonia in mlr

makeRLearner.classif.h2o_dl = function() { 
makeRLearnerClassif(
cl = "classif.h2o_dl", 
package = "h2o", 
par.set = makeParamSet(
    makeDiscreteLearnerParam(id = "activation", 
    values = c("Rectifier", "Tanh", "TanhWithDropout", "RectifierWithDropout", "Maxout", "MaxoutWithDropout")), 
    makeNumericLearnerParam(id = "epochs", default = 10, lower = 1), 
    makeNumericLearnerParam(id = "rate", default = 0.005, lower = 0, upper = 1), 
    makeIntegerVectorLearnerParam(id = "hidden", default = c(100,100)), 
    makeDiscreteLearnerParam(id = "loss", values = c("Automatic", 
      "CrossEntropy", "Quadratic", "Absolute", "Huber")) 
), 
properties = c("twoclass", "multiclass", "numerics", "factors", "prob","missings"), 
name = "Deep Learning Neural Network with h2o", 
short.name = "h2o_deeplearning_classif", 
note = "tbd" 
) 
} 

trainLearner.classif.h2o_dl = function(.learner, .task,.subset,.weights=NULL, ...) { 
f = getTaskFormula(.task) 
data = getTaskData(.task, .subset) 
data_h2o <- as.h2o(data, 
       destination_frame = paste0(
        "train_", 
        format(Sys.time(), "%m%d%y_%H%M%S"))) 
h2o::h2o.deeplearning(x = getTaskFeatureNames(.task), 
      y = setdiff(names(getTaskData(.task)), 
         getTaskFeatureNames(.task)), 
      training_frame = data_h2o, ...) 
} 

predictLearner.classif.h2o_dl = function(.learner, .model, .newdata, predict.method = "plug-in", ...) { 
data <- as.h2o(.newdata, 
      destination_frame = paste0("pred_", 
             format(Sys.time(), "%m%d%y_%H%M%S"))) 
p = predict(.model$learner.model, newdata = data, method = predict.method, ...) 
if (.learner$predict.type == "response") 
return(as.data.frame(p)[,1]) else return(as.matrix(as.numeric(p))[,-1]) 
} 

ho provato messa a punto del parametro 'nascosto' tramite ricerca a griglia per mezzo della funzione di makeDiscreteParam:

library(mlr) 
library(h2o) 
h2o.init() 

lrn.h2o <- makeLearner("classif.h2o_dl") 
n <- getTaskSize(sonar.task) 
train.set = seq(1, n, by = 2) 
test.set = seq(2, n, by = 2) 
mod.h2o = train(lrn.h2o, sonar.task, subset = train.set) 
pred.h2o <- predict(mod.h2o,task= sonar.task, subset = train.set) 

ctrl = makeTuneControlGrid() 
rdesc = makeResampleDesc("CV", iters = 3L) 
ps = makeParamSet(
makeDiscreteParam("hidden", values = list(c(10,10),c(100,100))), 
makeDiscreteParam("rate", values = c(0.1,0.5)) 
) 

res = tuneParams("classif.h2o_dl", task = sonar.task, resampling = rdesc,par.set = ps,control = ctrl) 

che ha portato il messaggio di avviso

Warning messages: 
1: In checkValuesForDiscreteParam(id, values) : 
number of items to replace is not a multiple of replacement length 
2: In checkValuesForDiscreteParam(id, values) : 
number of items to replace is not a multiple of replacement length 

e ps si presenta così:

ps 
      Type len Def Constr Req Tunable Trafo 
hidden discrete - - 10,100 - TRUE  - 
rate discrete - - 0.1,0.5 - TRUE  - 

che non risulta nell'ottimizzazione del parametro nascosto come vettore. Ho anche provato un'altra funzione di costruzione speciale (ad esempio makeNumericVectorParam) che non ha funzionato. Qualcuno ha esperienza nei vettori di ottimizzazione (integer) in mlr e potrebbe darmi un suggerimento?

+0

suona come è necessario utilizzare 'makeNumericVectorParam' qui. Puoi condividere il codice che hai provato che non ha funzionato, per favore? –

+0

Ho appena aggiunto il codice completo –

+0

Hmm, se si desidera provare solo quei valori specifici introdurrei un parametro fittizio che è semplicemente un indice nell'elenco di valori da provare e verificare/convertire quello nel wrapper per lo studente. –

risposta

Problemi correlati