jakob-r/mlrHyperopt

Problem tunning classif.knn and classif.lda with mlrHyperopt - Error in getDefaultParConfig(learner) !

Closed this issue · 2 comments

LGGom commented

Hi,
I'm trying to tunning HP of classif.knn and classif.lda on my data, with learners default values.
I gets this error: "Error in getDefaultParConfig(learner) : For the learner classif.knn no default is available." for classif.knn, and this one: "Error in getDefaultParConfig(learner) : For the learner classif.lda no default is available. for classif.lda.

The code I run for classif.knn HP tunning, as an example:

set.seed ( 123 )
task7 = makeClassifTask( data = train.fin.var, target = "Variedade")
task7

Supervised task: train.fin.var
Type: classif
Target: Variedade
Observations: 789
Features:
numerics factors ordered functionals
10 0 0 0
Missings: FALSE
Has weights: FALSE
Has blocking: FALSE
Has coordinates: FALSE
Classes: 10
Arbequina Azeiteira Carrasquenha Cobrancosa Cordovil Galega Koroneiki Picual
80 80 81 80 80 80 80 68
Redondil Verdeal
80 80
Positive class: NA

learner7 = makeLearner("classif.knn", predict.type = "response", fix.factors.prediction = TRUE)
getParamSet(learner7)

Type len Def Constr Req Tunable Trafo
k integer - 1 1 to Inf - TRUE -
l numeric - 0 0 to Inf - TRUE -
prob logical - FALSE - - FALSE -
use.all logical - TRUE - - TRUE -

knn.otim <- hyperopt(task7, learner = learner7 )

Error in getDefaultParConfig(learner) :
For the learner classif.knn no default is available.

There is any way I can solve this?

Thanks.

As the error says. mlrHyperopt has no default for the learner knn. You can configure a par.config yourself like that:

library(mlrHyperopt)
learner7 = makeLearner("classif.knn", predict.type = "response", fix.factors.prediction = TRUE)
par.set = makeParamSet(
  makeIntegerParam("k", lower = 1, upper = 30)
)
par.config = makeParConfig(par.set = par.set, learner = learner7)
knn.otim <- hyperopt(iris.task, par.config = par.config)
knn.otim

You can upload the par config with uploadParConfig(..., as.default = TRUE) so it will be stored in the online database and suggested as a default for that learner. Future calls of hyperopt(..., learner = "classif.knn") will then use this default (note that this is an experimental feature).

LGGom commented

Thanks for your help!