Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(check): better error message when measure's minimize is NA #485

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/helper.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
measures_to_codomain = function(measures) {
measures = as_measures(measures)
domains = map(measures, function(s) {
if (is.na(s$minimize)) {
stopf("Measure %s has its `minimize` field set to NA, which is disallowed when tuning.", s$id)
}
p_dbl(tags = ifelse(s$minimize, "minimize", "maximize"))
})
names(domains) = ids(measures)
Expand Down
1 change: 1 addition & 0 deletions man/AutoTuner.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/mlr_tuners_cmaes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/testthat/test_Tuner.R
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,15 @@ test_that("Can only pass internal tune tokens one way", {
term_evals = 2),
"Either tag parameters")
})

test_that("Correct error when minimize is NA", {
m = msr("classif.acc")
m$minimize = NA
expect_error(tune(
tuner = tnr("random_search"),
task = tsk("iris"),
learner = lrn("classif.debug", x = to_tune()),
resampling = rsmp("holdout"),
measure = m
), "`minimize`")
})
Loading