Skip to content

Commit

Permalink
add eval_time_target as an attribute (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
topepo authored Dec 12, 2023
1 parent 585e01d commit fc2a6b1
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tune
Title: Tidy Tuning Tools
Version: 1.1.2.9003
Version: 1.1.2.9004
Authors@R: c(
person("Max", "Kuhn", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2402-136X")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export(.estimate_metrics)
export(.filter_perf_metrics)
export(.get_extra_col_names)
export(.get_fingerprint)
export(.get_tune_eval_time_target)
export(.get_tune_eval_times)
export(.get_tune_metric_names)
export(.get_tune_metrics)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

* Improves documentation related to the hyperparameters associated with extracted objects that are generated from submodels. See the "Extracting with submodels" section of `?collect_extracts` to learn more.

* An `eval_time` attribute was added to tune objects. There is also a `.get_tune_eval_times()` function.
* `eval_time` and `eval_time_target` attribute was added to tune objects. There are also `.get_tune_eval_times()` and `.get_tune_eval_time_target()` functions.

* `augment()` methods to `tune_results`, `resample_results`, and `last_fit` objects now always returns tibbles (#759).

Expand Down
3 changes: 3 additions & 0 deletions R/compat-vctrs-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ new_tune_results_from_template <- function(x, to) {
parameters = attrs$parameters,
metrics = attrs$metrics,
eval_time = attrs$eval_time,
eval_time_target = attrs$eval_time_target,
outcomes = attrs$outcomes,
rset_info = attrs$rset_info
)
Expand Down Expand Up @@ -107,6 +108,7 @@ new_resample_results_from_template <- function(x, to) {
parameters = attrs$parameters,
metrics = attrs$metrics,
eval_time = attrs$eval_time,
eval_time_target = attrs$eval_time_target,
outcomes = attrs$outcomes,
rset_info = attrs$rset_info
)
Expand Down Expand Up @@ -137,6 +139,7 @@ new_iteration_results_from_template <- function(x, to) {
parameters = attrs$parameters,
metrics = attrs$metrics,
eval_time = attrs$eval_time,
eval_time_target = attrs$eval_time_target,
outcomes = attrs$outcomes,
rset_info = attrs$rset_info,
workflow = attrs$workflow
Expand Down
2 changes: 2 additions & 0 deletions R/iteration_results.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ new_iteration_results <-
parameters,
metrics,
eval_time,
eval_time_target,
outcomes = character(0),
rset_info,
workflow) {
Expand All @@ -41,6 +42,7 @@ new_iteration_results <-
parameters = parameters,
metrics = metrics,
eval_time = eval_time,
eval_time_target = eval_time_target,
outcomes = outcomes,
rset_info = rset_info,
workflow = workflow,
Expand Down
1 change: 1 addition & 0 deletions R/resample.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ resample_workflow <- function(workflow, resamples, metrics, control,
parameters = attributes$parameters,
metrics = attributes$metrics,
eval_time = attributes$eval_time,
eval_time_target = NULL,
outcomes = attributes$outcomes,
rset_info = attributes$rset_info,
workflow = attributes$workflow
Expand Down
2 changes: 2 additions & 0 deletions R/resample_results.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ new_resample_results <-
parameters,
metrics,
eval_time,
eval_time_target = NULL,
outcomes = character(0),
rset_info,
workflow = NULL) {
Expand All @@ -27,6 +28,7 @@ new_resample_results <-
parameters = parameters,
metrics = metrics,
eval_time = eval_time,
eval_time_target = eval_time_target,
outcomes = outcomes,
rset_info = rset_info,
workflow = workflow,
Expand Down
2 changes: 2 additions & 0 deletions R/tune_bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ tune_bayes_workflow <-
parameters = param_info,
metrics = metrics,
eval_time = eval_time,
eval_time_target = metrics_time,
outcomes = outcomes,
rset_info = rset_info,
workflow = NULL
Expand Down Expand Up @@ -479,6 +480,7 @@ tune_bayes_workflow <-
parameters = param_info,
metrics = metrics,
eval_time = eval_time,
eval_time_target = metrics_time,
outcomes = outcomes,
rset_info = rset_info,
workflow = workflow_output
Expand Down
1 change: 1 addition & 0 deletions R/tune_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ tune_grid_workflow <- function(workflow,
parameters = pset,
metrics = metrics,
eval_time = eval_time,
eval_time_target = NULL,
outcomes = outcomes,
rset_info = rset_info,
workflow = workflow
Expand Down
2 changes: 2 additions & 0 deletions R/tune_results.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ new_tune_results <-
parameters,
metrics,
eval_time,
eval_time_target,
outcomes = character(0),
rset_info,
...,
Expand All @@ -111,6 +112,7 @@ new_tune_results <-
parameters = parameters,
metrics = metrics,
eval_time = eval_time,
eval_time_target = eval_time_target,
outcomes = outcomes,
rset_info = rset_info,
...,
Expand Down
11 changes: 11 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ new_bare_tibble <- function(x, ..., class = character()) {
res
}

#' @export
#' @rdname tune_accessor
.get_tune_eval_time_target <- function(x) {
x <- attributes(x)
if (any(names(x) == "eval_time_target")) {
res <- x$eval_time_target
} else {
res <- NULL
}
res
}

#' @export
#' @rdname tune_accessor
Expand Down
1 change: 1 addition & 0 deletions man/empty_ellipses.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/tune_accessor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test-bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ test_that("tune recipe only", {
expect_false(identical(num_comp, expr(tune())))
expect_true(res_workflow$trained)
expect_null(.get_tune_eval_times(res))
expect_null(.get_tune_eval_time_target(res))

set.seed(1)
expect_error(
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test_that("tune recipe only", {
expect_false(identical(num_comp, expr(tune())))
expect_true(res_workflow$trained)
expect_null(.get_tune_eval_times(res))
expect_null(.get_tune_eval_time_target(res))
})

# ------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-last-fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test_that("formula method", {
nrow(rsample::testing(split))
)
expect_null(.get_tune_eval_times(res))
expect_null(.get_tune_eval_time_target(res))

})

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-resample.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test_that("`fit_resamples()` returns a `resample_result` object", {
expect_equal(result, .Last.tune.result)

expect_null(.get_tune_eval_times(result))
expect_null(.get_tune_eval_time_target(result))
})

test_that("can use `fit_resamples()` with a formula", {
Expand Down

0 comments on commit fc2a6b1

Please sign in to comment.