Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
handle failing models
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-r committed May 8, 2017
1 parent dcb16df commit 2797a37
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Suggests:
randomForest,
DiceKriging,
rgenoud,
knitr
knitr,
gbm
VignetteBuilder: knitr
RoxygenNote: 6.0.1
3 changes: 2 additions & 1 deletion R/generateHyperControl.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ generateHyperControl = function(task, par.config = NULL, learner = NULL, budget.
} else if (
all(getParamTypes(par.set) %in% c("numeric", "integer", "numericvector", "integervector")) &&
getParamNr(par.set) * 4 < budget.evals * 0.75) {
mbo.control = mlrMBO::makeMBOControl(final.method = "best.predicted")
imputeWorst = function(x, y, opt.path, c = 2) c * max(getOptPathY(opt.path), na.rm = TRUE)
mbo.control = mlrMBO::makeMBOControl(final.method = "best.predicted", impute.y.fun = imputeWorst)
mbo.control = mlrMBO::setMBOControlInfill(mbo.control, crit = mlrMBO::crit.eqi)
mbo.control = mlrMBO::setMBOControlTermination(mbo.control, max.evals = budget.evals)
mlr.control = makeTuneControlMBO(mbo.control = mbo.control, mbo.keep.result = TRUE)
Expand Down
2 changes: 2 additions & 0 deletions R/hyperopt.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ hyperopt = function(task, learner = NULL, par.config = NULL, hyper.control = NUL
if ("req.prob" %in% measures[[1]]$properties) {
learner = setPredictType(learner, "prob")
}
learner$config = insert(learner$config, list(on.learner.error = "warn"))


tune.res = tuneParams(
learner = learner,
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test_hyperopt.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ test_that("hyperopt works", {
res3 = hyperopt(mini.task, par.config = par.config)
expect_class(res3, "TuneResult")
expect_class(res3$control, "TuneControlGrid")
})

test_that("hyperopt works with failing learners", {
mlr::configureMlr(show.info = FALSE, show.learner.output = FALSE)
# should trigger MBO
lrn = makeLearner("classif.gbm")
task = iris.task
res = hyperopt(task = iris.task, learner = lrn)
expect_class(res, "TuneResult")
expect_class(res$control, "TuneControlMBO")
expect_number(res$y, lower = 0, upper = 0.1)
expect_true(any(is.na(getOptPathY(res$opt.path))))
})

0 comments on commit 2797a37

Please sign in to comment.