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

align .config entries in tune_bayes() output #718

Merged
merged 5 commits into from
Sep 8, 2023
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* A method for rsample's `int_pctl()` function that will compute percentile confidence intervals on performance metrics for objects produced by `fit_resamples()`, `tune_*()`, and `last_fit()`.

* Fixes bug where `.config` entries in the `.extracts` column in `tune_bayes()` output didn't align with the entries they ought to in the `.metrics` and `.predictions` columns (#715).

# tune 1.1.2

* `last_fit()` now works with the 3-way validation split objects from `rsample::initial_validation_split()`. `last_fit()` and `fit_best()` now have a new argument `add_validation_set` to include or exclude the validation set in the dataset used to fit the model (#701).
Expand Down
6 changes: 6 additions & 0 deletions R/tune_bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ tune_bayes_workflow <-
~ dplyr::mutate(., .config = paste0("Iter", i))
)
}
if (".extracts" %in% names(tmp_res)) {
tmp_res[[".extracts"]] <- purrr::map(
tmp_res[[".extracts"]],
~ dplyr::mutate(., .config = paste0("Iter", i))
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The substance of the PR is here and in the untouched lines above; we just need to make the same mutate() happen in .extracts that happened already for .metrics and .predictions.

unsummarized <- dplyr::bind_rows(unsummarized, tmp_res %>% mutate(.iter = i))
rs_estimate <- estimate_tune_results(tmp_res)
mean_stats <- dplyr::bind_rows(mean_stats, rs_estimate %>% dplyr::mutate(.iter = i))
Expand Down
Binary file modified tests/testthat/data/test_objects.RData
Binary file not shown.
19 changes: 19 additions & 0 deletions tests/testthat/test-extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ test_that("check .config in extracts", {
expect_true(any(names(mt_spln_lm_bo$.extracts[[i]]) == ".config"))
}

recipe_only_configs <-
full_join(
mt_spln_lm_bo %>%
filter(id == first(id)) %>%
select(.iter, .metrics) %>%
unnest(cols = .metrics) %>%
filter(.metric == first(.metric)),
mt_spln_lm_bo %>%
filter(id == first(id)) %>%
select(.iter, .extracts) %>%
unnest(cols = .extracts),
by = c(".iter", "deg_free")
)

expect_equal(
recipe_only_configs$.config.x,
recipe_only_configs$.config.y
)

# recipe and model
for (i in 1:nrow(mt_spln_knn_grid)) {
expect_true(any(names(mt_spln_knn_grid$.extracts[[i]]) == ".config"))
Expand Down