Skip to content

Commit

Permalink
respect show.info in resample printer (fixes #1963) (#1974)
Browse files Browse the repository at this point in the history
  • Loading branch information
larskotthoff authored and jakob-r committed Aug 8, 2017
1 parent 959588e commit 3a320a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
22 changes: 12 additions & 10 deletions R/resample.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,20 @@ resample = function(learner, task, resampling, measures, weights = NULL, models
parallelLibrary("mlr", master = FALSE, level = "mlr.resample", show.info = FALSE)
exportMlrOptions(level = "mlr.resample")

messagef("Resampling: %s", rin$desc$id)
if (show.info) {
messagef("Resampling: %s", rin$desc$id)

measure.lognames = extractSubList(measures, "id")
# when predict on both some measure might be in there twice,
# depending on aggregation fun, then we need to print each measure twice
if (rin$desc$predict == "both") {
id.train = which(vlapply(measures, function(x) "req.train" %in% x$aggr$properties))
id.test = which(vlapply(measures, function(x) "req.test" %in% x$aggr$properties))
measure.lognames = c(stri_paste(measure.lognames[id.train], "train", sep = "."),
stri_paste(measure.lognames[id.test], "test", sep = "."))
measure.lognames = extractSubList(measures, "id")
# when predict on both some measure might be in there twice,
# depending on aggregation fun, then we need to print each measure twice
if (rin$desc$predict == "both") {
id.train = which(vlapply(measures, function(x) "req.train" %in% x$aggr$properties))
id.test = which(vlapply(measures, function(x) "req.test" %in% x$aggr$properties))
measure.lognames = c(stri_paste(measure.lognames[id.train], "train", sep = "."),
stri_paste(measure.lognames[id.test], "test", sep = "."))
}
printResampleFormatLine("Measures:", measure.lognames)
}
printResampleFormatLine("Measures:", measure.lognames)

time1 = Sys.time()
iter.results = parallelMap(doResampleIteration, seq_len(rin$desc$iters), level = "mlr.resample", more.args = more.args)
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test_base_resample.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,16 @@ test_that("resample is extended by an additional measure", {
res = resample(lrn, binaryclass.task, cv3, mmce, keep.pred = FALSE)
expect_error(addRRMeasure(res, auc), "keep.pred")
})

test_that("resample printer respects show.info", {
show.info.saved = getMlrOptions()$show.info
lrn = makeLearner("regr.lm")

configureMlr(show.info = TRUE)
expect_message(resample(lrn, bh.task, cv10, list(mape, medae, mse)))

configureMlr(show.info = FALSE)
expect_silent(resample(lrn, bh.task, cv10, list(mape, medae, mse)))

configureMlr(show.info = show.info.saved)
})

0 comments on commit 3a320a3

Please sign in to comment.