-
Notifications
You must be signed in to change notification settings - Fork 16
butcher methods for rsample objects #293
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
37dbbc8
roxygen2 updates
topepo dec0669
add generics
topepo e01841f
add methods for removing data
topepo 55e8ded
add indicators
topepo 705fbfc
unit tests
topepo a43009a
remove devel namespacing
topepo e1852c4
news entry
topepo 5403277
Merge branch 'main' into rsample-tune-workflow-sets
topepo 9e715cd
Merge branch 'main' into rsample-tune-workflow-sets
topepo 4d04c37
Apply suggestions from code review
topepo c06d314
updated tests and redoc
topepo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| #' @rdname axe-rsample-data | ||
| #' @export | ||
| axe_rsample_data.rsplit <- function(x, verbose = FALSE, ...) { | ||
| old <- x | ||
| x <- zero_data(x) | ||
| add_butcher_attributes( | ||
| x, | ||
| old, | ||
| disabled = c( | ||
| "analysis()", | ||
| "as.data.frame()", | ||
| "as.integer()", | ||
| "assessment()", | ||
| "complement()", | ||
| "internal_calibration_split()", | ||
| "populate()", | ||
| "reverse_splits()", | ||
| "testing()", | ||
| "tidy()", | ||
| "training()" | ||
| ), | ||
| verbose = verbose | ||
| ) | ||
| } | ||
|
|
||
| #' @rdname axe-rsample-data | ||
| #' @export | ||
| axe_rsample_data.three_way_split <- function(x, verbose = FALSE, ...) { | ||
| old <- x | ||
| x <- zero_data(x) | ||
| add_butcher_attributes( | ||
| x, | ||
| old, | ||
| disabled = c( | ||
| "internal_calibration_split()", | ||
| "testing()", | ||
| "training()", | ||
| "validation()" | ||
| ), | ||
| verbose = verbose | ||
| ) | ||
| } | ||
|
|
||
| #' @rdname axe-rsample-data | ||
| #' @export | ||
| axe_rsample_data.rset <- function(x, verbose = FALSE, ...) { | ||
| old <- x | ||
|
|
||
| if (any(names(x) == "splits")) { | ||
| x$splits <- purrr::map(x$splits, axe_rsample_data) | ||
| } | ||
|
|
||
| add_butcher_attributes( | ||
| x, | ||
| old, | ||
| disabled = c("populate()", "reverse_splits()", "tidy()"), | ||
| verbose = verbose | ||
| ) | ||
| } | ||
|
|
||
| #' @rdname axe-rsample-data | ||
| #' @export | ||
| axe_rsample_data.tune_results <- function(x, verbose = FALSE, ...) { | ||
| old <- x | ||
|
|
||
| if (any(names(x) == "splits")) { | ||
| x$splits <- purrr::map(x$splits, axe_rsample_data) | ||
| } | ||
|
|
||
| add_butcher_attributes( | ||
| x, | ||
| old, | ||
| disabled = c("augment()", "fit_best()"), | ||
| verbose = verbose | ||
| ) | ||
| } | ||
|
|
||
| #' @rdname axe-rsample-data | ||
| #' @export | ||
| axe_rsample_data.workflow_set <- function(x, verbose = FALSE, ...) { | ||
| has_res <- purrr::map_lgl(x$result, ~ inherits(.x, "tune_results")) | ||
| if (!any(has_res)) { | ||
| return(x) | ||
| } | ||
| old <- x | ||
|
|
||
| for (i in which(has_res)) { | ||
| x$result[[i]] <- axe_rsample_data(x$result[[i]]) | ||
| } | ||
|
|
||
| add_butcher_attributes( | ||
| x, | ||
| old, | ||
| disabled = c("augment()", "fit_best()"), | ||
| verbose = verbose | ||
| ) | ||
| } | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
|
|
||
| zero_data <- function(split) { | ||
| split$data <- split$data[0, , drop = FALSE] | ||
| split | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| #' @rdname axe-rsample-indicators | ||
| #' @export | ||
| axe_rsample_indicators.rsplit <- function(x, verbose = FALSE, ...) { | ||
| old <- x | ||
| x <- zero_all_ind(x) | ||
| add_butcher_attributes( | ||
| x, | ||
| old, | ||
| disabled = c( | ||
| "analysis()", | ||
| "as.data.frame()", | ||
| "as.integer()", | ||
| "assessment()", | ||
| "complement()", | ||
topepo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "internal_calibration_split()", | ||
| "populate()", | ||
| "reverse_splits()", | ||
| "testing()", | ||
| "tidy()", | ||
| "training()" | ||
| ), | ||
| verbose = verbose | ||
| ) | ||
| } | ||
|
|
||
| #' @rdname axe-rsample-indicators | ||
| #' @export | ||
| axe_rsample_indicators.three_way_split <- function(x, verbose = FALSE, ...) { | ||
| old <- x | ||
| x <- zero_all_ind(x) | ||
| add_butcher_attributes( | ||
| x, | ||
| old, | ||
| disabled = c( | ||
| "internal_calibration_split()", | ||
| "testing()", | ||
| "training()", | ||
| "validation()" | ||
| ), | ||
| verbose = verbose | ||
| ) | ||
| } | ||
|
|
||
| #' @rdname axe-rsample-indicators | ||
| #' @export | ||
| axe_rsample_indicators.rset <- function(x, verbose = FALSE, ...) { | ||
| old <- x | ||
|
|
||
| if (any(names(x) == "splits")) { | ||
| x$splits <- purrr::map(x$splits, axe_rsample_indicators) | ||
| } | ||
|
|
||
| add_butcher_attributes( | ||
| x, | ||
| old, | ||
| disabled = c("populate()", "reverse_splits()", "tidy()"), | ||
| verbose = verbose | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| #' @rdname axe-rsample-indicators | ||
| #' @export | ||
| axe_rsample_indicators.tune_results <- function(x, verbose = FALSE, ...) { | ||
| old <- x | ||
| if (any(names(x) == "splits")) { | ||
| x$splits <- purrr::map(x$splits, axe_rsample_indicators) | ||
| } | ||
| add_butcher_attributes( | ||
| x, | ||
| old, | ||
| disabled = c("augment()", "fit_best()"), | ||
| verbose = verbose | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| #' @rdname axe-rsample-indicators | ||
| #' @export | ||
| axe_rsample_indicators.workflow_set <- function(x, verbose = FALSE, ...) { | ||
| has_res <- purrr::map_lgl(x$result, ~ inherits(.x, "tune_results")) | ||
| if (!any(has_res)) { | ||
| return(x) | ||
| } | ||
|
|
||
| old <- x | ||
|
|
||
| for (i in which(has_res)) { | ||
| x$result[[i]] <- axe_rsample_indicators(x$result[[i]]) | ||
| } | ||
|
|
||
| add_butcher_attributes( | ||
| x, | ||
| old, | ||
| disabled = c("augment()", "fit_best()"), | ||
| verbose = verbose | ||
| ) | ||
| } | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
|
|
||
| zero_ind <- function(ind) { | ||
| if (!all(is.na(ind))) { | ||
| ind <- integer(0) | ||
| } | ||
| ind | ||
| } | ||
|
|
||
| zero_all_ind <- function(split) { | ||
| ind_nms <- grep("_id$", names(split), value = TRUE) | ||
| for (nm in ind_nms) { | ||
| split[[nm]] <- zero_ind(split[[nm]]) | ||
| } | ||
| split | ||
| } | ||
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.