Skip to content

Commit bcc616c

Browse files
authored
Merge pull request #51 from tdhock/fix50
consistent plot methods
2 parents 3f29419 + a9a2ceb commit bcc616c

File tree

7 files changed

+68
-9
lines changed

7 files changed

+68
-9
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: mlr3resampling
22
Type: Package
33
Title: Resampling Algorithms for 'mlr3' Framework
4-
Version: 2025.9.24
4+
Version: 2025.11.19
55
Encoding: UTF-8
66
Authors@R: c(
77
person("Toby", "Hocking",

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Changes in version 2025.11.19 (PR#51)
2+
3+
- plot() yields consistent Y axes (other on top) for score() and pvalue().
4+
15
Changes in version 2025.9.24
26

37
- Newer resamplers vignette reproducibility section.

R/ResamplingSameOtherSizesCV.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ ResamplingSameOtherSizesCV = R6::R6Class(
172172
}
173173
}
174174
list(
175-
iteration.dt=rbindlist(
176-
iteration.dt.list
177-
)[, iteration := .I][],
175+
iteration.dt=rbindlist(iteration.dt.list)[, let(
176+
iteration = .I,
177+
Train_subsets = factor(train.subsets, c("all","same","other"))
178+
)][],
178179
fold.dt=fold.dt)
179180
}
180181
)

R/pvalue.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ plot.pvalue <- function(x, ..., text.size=5, p.color="grey50", sd.seg.size=1){
129129
hi,
130130
Train_subsets,
131131
xend=lo, yend=Train_subsets),
132-
size=sd.seg.size,
132+
linewidth=sd.seg.size,
133133
data=x$stats)+
134134
ggplot2::geom_segment(ggplot2::aes(
135135
compare_mean, Train_subsets,

R/score.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ score <- function(bench.result, ...){
2222
}
2323

2424
plot.score <- function(x, ..., value.var=NULL){
25-
value <- train.subsets <- NULL
25+
value <- Train_subsets <- NULL
2626
if(requireNamespace("ggplot2")){
2727
if(is.null(value.var)){
2828
value.var <- grep("classif|regr", names(x), value=TRUE)[1]
2929
}
3030
dt <- data.table(x)[, value := get(value.var)][]
3131
ggplot2::ggplot()+
3232
ggplot2::geom_point(ggplot2::aes(
33-
value, train.subsets),
33+
value, Train_subsets),
3434
shape=1,
3535
data=dt)+
3636
ggplot2::facet_grid(

tests/testthat/test-CRAN.R

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,12 @@ test_that("proj_test down-samples proportionally", {
663663
expect_equal(sum(is.na(rpart_dt[["iteration"]])), 0)
664664
})
665665

666-
test_that("set works after score", {
666+
last_lev <- function(x){
667+
levs <- levels(factor(x))
668+
levs[length(levs)]
669+
}
670+
671+
test_that("set works after score(), other is last Y level", {
667672
N <- 80
668673
set.seed(1)
669674
reg.dt <- data.table(
@@ -696,6 +701,52 @@ test_that("set works after score", {
696701
SOAK))
697702
bench.result <- mlr3::benchmark(bench.grid)
698703
bench.score <- mlr3resampling::score(bench.result, mlr3::msr("regr.rmse"))
704+
if(interactive())plot(bench.score)
699705
set(bench.score, j="foo", value=1)
700706
expect_is(bench.score, "score")
707+
expect_identical(last_lev(bench.score$Train_subsets), "other")
708+
bench.pvalue <- mlr3resampling::pvalue(bench.score)
709+
if(interactive())plot(bench.pvalue)
710+
expect_identical(last_lev(bench.pvalue$stats$Train_subsets), "other")
711+
})
712+
713+
test_that("plot ok without other", {
714+
N <- 80
715+
set.seed(1)
716+
reg.dt <- data.table(
717+
x=runif(N, -2, 2),
718+
person=rep(1:2, each=0.5*N))
719+
reg.pattern.list <- list(
720+
easy=function(x, person)x^2,
721+
impossible=function(x, person)(x^2)*(-1)^person)
722+
SAK <- mlr3resampling::ResamplingSameOtherSizesCV$new()
723+
SAK$param_set$values$subsets <- "SA"
724+
reg.task.list <- list()
725+
for(pattern in names(reg.pattern.list)){
726+
f <- reg.pattern.list[[pattern]]
727+
yname <- paste0("y_",pattern)
728+
reg.dt[, (yname) := f(x,person)+rnorm(N, sd=0.5)][]
729+
task.dt <- reg.dt[, c("x","person",yname), with=FALSE]
730+
task.obj <- mlr3::TaskRegr$new(
731+
pattern, task.dt, target=yname)
732+
task.obj$col_roles$stratum <- "person"
733+
task.obj$col_roles$subset <- "person"
734+
reg.task.list[[pattern]] <- task.obj
735+
}
736+
reg.learner.list <- list(
737+
mlr3::LearnerRegrFeatureless$new())
738+
if(requireNamespace("rpart")){
739+
reg.learner.list$rpart <- mlr3::LearnerRegrRpart$new()
740+
}
741+
(bench.grid <- mlr3::benchmark_grid(
742+
reg.task.list,
743+
reg.learner.list,
744+
SAK))
745+
bench.result <- mlr3::benchmark(bench.grid)
746+
bench.score <- mlr3resampling::score(bench.result, mlr3::msr("regr.rmse"))
747+
if(interactive())plot(bench.score)
748+
expect_identical(last_lev(bench.score$Train_subsets), "same")
749+
bench.pvalue <- mlr3resampling::pvalue(bench.score)
750+
if(interactive())plot(bench.pvalue)
751+
expect_identical(last_lev(bench.pvalue$stats$Train_subsets), "same")
701752
})

tests/testthat/test-mlr3torch.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
library(testthat)
2+
library(data.table)
3+
14
test_that("mlr3torch history saved", {
25
N <- 80
36
set.seed(1)
@@ -92,7 +95,7 @@ test_that("mlr3torch history saved", {
9295
expected_join_cols <- c(
9396
expected_csv_cols,
9497
"task_id", "learner_id", "resampling_id", "test.subset", "train.subsets",
95-
"groups", "test.fold", "seed", "n.train.groups", "iteration")
98+
"groups", "test.fold", "seed", "n.train.groups", "iteration", "Train_subsets")
9699
expect_identical(names(csv_data_list$learners.csv), expected_join_cols)
97100
})
98101

0 commit comments

Comments
 (0)