problem
I want to do a grid search with different hyperparameters that are provided by a self-made grid. But when I am running the code I get a warning: "Unknown or uninitialised column: ntree
."
example data
age <- c(round(rnorm(120,mean = 50,sd = 10)))
sex <- c(round(rnorm(120,mean = 0.5,sd = 0.2)))
l1 <- as.logical(c(round(rnorm(120,mean = 0.5,sd = 0.2))))
l2 <- as.logical(c(round(rnorm(120,mean = 0.5,sd = 0.2))))
l3 <- as.logical(c(round(rnorm(120,mean = 0.5,sd = 0.2))))
l4 <- as.logical(c(round(rnorm(120,mean = 0.5,sd = 0.2))))
data <- as.data.frame(cbind(age,sex,l1,l2,l3,l4))
In reality I have 12 labels, but I left the others out to make it easier to look at. The idea is that l1 untill l4 are logical vectors. Somehow that doesn't work, so I hope you can fix that. But be aware that that is not my main question.
create grid
gs <- list(ntree = c(50,100,150,200,300,500,550),mtry = c(1,2,3,4,5)) %>% cross_df()
select hyperparameters
for (h in 1:nrow(gs)) {
ntree_entry <- gs$ntree[h]
mtry_entry <- gs$mtry[h]
(...)
lrn <- makeMultilabelClassifierChainsWrapper(lrn, order = NULL)
lrn <- setPredictType(lrn,"prob")
task <- makeMultilabelTask(data = data[train_lines,], target = label_bact)
mod <- mlr::train(lrn,task)
}
On the place of (...) I have tried two different ways to get the hyperparameters into the learner:
option 1: pass hyperparameters to the learner
lrn <- makeLearner("classif.randomForest",ntree = ntree_entry,mtry = mtry_entry)
option 2: pass hyperparameters to the learner
lrn <- makeLearner("classif.randomForest")
lrn <- setHyperPars(lrn,par.vals = list(ntree = ntree_entry,mtry = mtry_entry))
check
The console tells me that the hyperparameters are in the learner:
>lrn
Learner classif.randomForest from package randomForest
Type: classif
Name: Random Forest; Short name: rf
Class: classif.randomForest
Properties: twoclass,multiclass,numerics,factors,ordered,prob,class.weights,oobpreds,featimp
Predict-Type: response
Hyperparameters: ntree=50,mtry=1
ntree and mtry are hyperparameters that are known to the makeLearner, because they are both in getParamSet:
> getParamSet("classif.randomForest")
Type len Def Constr Req Tunable Trafo
ntree integer - 500 1 to Inf - TRUE -
mtry integer - - 1 to Inf - TRUE -
replace logical - TRUE - - TRUE -
classwt numericvector <NA> - 0 to Inf - TRUE -
cutoff numericvector <NA> - 0 to 1 - TRUE -
strata untyped - - - - FALSE -
sampsize integervector <NA> - 1 to Inf - TRUE -
nodesize integer - 1 1 to Inf - TRUE -
maxnodes integer - - 1 to Inf - TRUE -
importance logical - FALSE - - TRUE -
localImp logical - FALSE - - TRUE -
proximity logical - FALSE - - FALSE -
oob.prox logical - - - Y FALSE -
norm.votes logical - TRUE - - FALSE -
do.trace logical - FALSE - - FALSE -
keep.forest logical - TRUE - - FALSE -
keep.inbag logical - FALSE - - FALSE -
Question
Why do I get the message "Unknown or uninitialised column: ntree
"?
Although it is only a warning, not an error, I am afraid that it will only use the first line of the grid that I created. The size of the models seem to confirm that. They all have the same size.
I hope that someone can help me with this problem.
Thanks in advance!