Skip to content

Commit

Permalink
test fails for train strata counts
Browse files Browse the repository at this point in the history
  • Loading branch information
tdhock committed Jan 21, 2024
1 parent 119a8f6 commit 3cd9119
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/testthat/test-CRAN.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
library(testthat)
library(data.table)
test_that("resampling error if no group", {
itask <- mlr3::TaskClassif$new("iris", iris, target="Species")
same_other <- mlr3resampling::ResamplingSameOtherCV$new()
Expand Down Expand Up @@ -92,6 +94,30 @@ test_that("error for 10 data", {
fixed=TRUE)
})

test_that("strata respected in all sizes", {
size_cv <- mlr3resampling::ResamplingVariableSizeTrainCV$new()
size_cv$param_set$values$min_train_data <- 5
size_cv$param_set$values$folds <- 5
N <- 100
imbalance <- 4
strat.vec <- ifelse((1:imbalance)<imbalance, "A","B")
istrat.dt <- data.table(iris[1:N,], strat=factor(rep(strat.vec, l=N)))
smallest.size.tab <- table(
istrat.dt[["strat"]]
)/N*imbalance*size_cv$param_set$values$min_train_data
istrat.task <- mlr3::TaskClassif$new(
"istrat", istrat.dt, target="Species"
)$set_col_roles("strat", "stratum")
size_cv$instantiate(istrat.task)
min.dt <- size_cv$instance$iteration.dt[train_size==min(train_size)]
for(min.i in 1:nrow(min.dt)){
min.row <- min.dt[min.i]
train.i <- min.row$train[[1]]
strat.tab <- table(istrat.dt[train.i, strat])
expect_identical(strat.tab, smallest.size.tab)
}
})

test_that("train set max size 67 for 100 data", {
size_cv <- mlr3resampling::ResamplingVariableSizeTrainCV$new()
i100.dt <- data.table(iris)[1:100]
Expand Down

0 comments on commit 3cd9119

Please sign in to comment.