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

transition from add_tailor(prop) and method #945

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Suggests:
Remotes:
tidymodels/rsample,
tidymodels/tailor,
tidymodels/workflows
tidymodels/workflows#262
Config/Needs/website: pkgdown, tidymodels, kknn, doParallel, doFuture,
tidyverse/tidytemplate
Config/testthat/edition: 3
Expand Down
7 changes: 1 addition & 6 deletions R/grid_code_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ tune_grid_loop_iter <- function(split,
assessment_rows <- as.integer(split, data = "assessment")
assessment <- vctrs::vec_slice(split$data, assessment_rows)

if (workflows::.should_inner_split(workflow)) {
if (workflows::.workflow_includes_calibration(workflow)) {
# if the workflow has a postprocessor that needs training (i.e. calibration),
# further split the analysis data into an "inner" analysis and
# assessment set.
Expand All @@ -397,11 +397,6 @@ tune_grid_loop_iter <- function(split,
# calibration set
# * the model (including the post-processor) generates predictions on the
# assessment set and those predictions are assessed with performance metrics
# todo: check if workflow's `method` is incompatible with `class(split)`?
# todo: workflow's `method` is currently ignored in favor of the one
# automatically dispatched to from `split`. consider this is combination
# with above todo.
split_args <- c(split_args, list(prop = workflow$post$actions$tailor$prop))
split <- rsample::inner_split(split, split_args = split_args)
analysis <- rsample::analysis(split)

Expand Down
20 changes: 12 additions & 8 deletions tests/testthat/test-last-fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ test_that("can use `last_fit()` with a workflow - postprocessor (requires traini
parsnip::linear_reg()
) %>%
workflows::add_tailor(
tailor::tailor("regression") %>% tailor::adjust_numeric_calibration("linear"),
prop = 2/3,
method = class(split)
tailor::tailor() %>% tailor::adjust_numeric_calibration("linear")
)

set.seed(1)
Expand All @@ -261,13 +259,21 @@ test_that("can use `last_fit()` with a workflow - postprocessor (requires traini
last_fit_preds <- collect_predictions(last_fit_res)

set.seed(1)
wflow_res <- generics::fit(wflow, rsample::analysis(split))
inner_split <- rsample::inner_split(split, split_args = list())

set.seed(1)
wflow_res <-
generics::fit(
wflow,
rsample::analysis(inner_split),
calibration = rsample::assessment(inner_split)
)
wflow_preds <- predict(wflow_res, rsample::assessment(split))

expect_equal(last_fit_preds[".pred"], wflow_preds)
})

test_that("can use `last_fit()` with a workflow - postprocessor (requires training)", {
test_that("can use `last_fit()` with a workflow - postprocessor (does not require training)", {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests the same thing it used to—it was just previously mislabeled.

skip_if_not_installed("tailor")

y <- seq(0, 7, .001)
Expand All @@ -284,9 +290,7 @@ test_that("can use `last_fit()` with a workflow - postprocessor (requires traini
parsnip::linear_reg()
) %>%
workflows::add_tailor(
tailor::tailor("regression") %>% tailor::adjust_numeric_range(lower_limit = 1),
prop = 2/3,
method = class(split)
tailor::tailor() %>% tailor::adjust_numeric_range(lower_limit = 1)
)

set.seed(1)
Expand Down
20 changes: 15 additions & 5 deletions tests/testthat/test-resample.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ test_that("can use `fit_resamples()` with a workflow - postprocessor (requires t
parsnip::linear_reg()
) %>%
workflows::add_tailor(
tailor::tailor("regression") %>% tailor::adjust_numeric_calibration("linear"),
prop = 2/3,
method = class(folds$splits[[1]])
tailor::tailor() %>% tailor::adjust_numeric_calibration("linear")
)

set.seed(1)
Expand All @@ -178,8 +176,20 @@ test_that("can use `fit_resamples()` with a workflow - postprocessor (requires t
seed <- generate_seeds(TRUE, 1)[[1]]
old_kind <- RNGkind()[[1]]
assign(".Random.seed", seed, envir = globalenv())
withr::defer(RNGkind(kind = old_kind))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An RNG state oddity—without it, tests elsewhere in the test suite begin failing with RNG changes.


wflow_res <- generics::fit(wflow, rsample::analysis(folds$splits[[1]]))
inner_split_1 <-
rsample::inner_split(
folds$splits[[1]],
split_args = list(v = 2, repeats = 1, breaks = 4, pool = 0.1)
)

wflow_res <-
generics::fit(
wflow,
rsample::analysis(inner_split_1),
calibration = rsample::assessment(inner_split_1)
)
wflow_preds <- predict(wflow_res, rsample::assessment(folds$splits[[1]]))

tune_wflow$fit$fit$elapsed$elapsed <- wflow_res$fit$fit$elapsed$elapsed
Expand All @@ -201,7 +211,7 @@ test_that("can use `fit_resamples()` with a workflow - postprocessor (no trainin
parsnip::linear_reg()
) %>%
workflows::add_tailor(
tailor::tailor("regression") %>% tailor::adjust_numeric_range(lower_limit = 1)
tailor::tailor() %>% tailor::adjust_numeric_range(lower_limit = 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the deprecated type argument in tailor code I was editing and went ahead and did it in the last remaining couple places.

)

set.seed(1)
Expand Down
Loading