Skip to content

Commit

Permalink
remove missing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
‘topepo’ committed Apr 25, 2024
1 parent 3cab3e0 commit 917196f
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 56 deletions.
10 changes: 5 additions & 5 deletions R/container.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Declare post-processing for model predictions
#'
#' @param mode The model's mode, one of `"unknown"`, `"classification"`, or
#' `"regression"`. Modes of `"censored regression"` are not currently supported.
#' @param mode The model's mode, one of `"classification"`, or `"regression"`.
#' Modes of `"censored regression"` are not currently supported.
#' @param type The model sub-type. Possible values are `"unknown"`, `"regression"`,
#' `"binary"`, or `"multiclass"`.
#' @param outcome The name of the outcome variable.
Expand All @@ -14,9 +14,9 @@
#' @param time The name of the predicted event time. (not yet supported)
#' @examples
#'
#' container()
#' container(mode = "regression")
#' @export
container <- function(mode = "unknown", type = "unknown", outcome = character(0),
container <- function(mode, type = "unknown", outcome = character(0),
estimate = character(0), probabilities = character(0),
time = character(0)) {
columns <-
Expand All @@ -39,7 +39,7 @@ container <- function(mode = "unknown", type = "unknown", outcome = character(0)
}

new_container <- function(mode, type, operations, columns, ptype, call) {
mode <- arg_match0(mode, c("unknown", "regression", "classification", "censored regression"))
mode <- arg_match0(mode, c("regression", "classification"))

if (mode == "regression") {
type <- "regression"
Expand Down
8 changes: 4 additions & 4 deletions man/container.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/adjust-equivocal-zone.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# adjustment printing

Code
container() %>% adjust_equivocal_zone()
ctr_cls %>% adjust_equivocal_zone()
Message
-- Container -------------------------------------------------------------------
Expand All @@ -12,7 +12,7 @@
---

Code
container() %>% adjust_equivocal_zone(hardhat::tune())
ctr_cls %>% adjust_equivocal_zone(hardhat::tune())
Message
-- Container -------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/adjust-numeric-calibration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# adjustment printing

Code
container() %>% adjust_numeric_calibration(dummy_reg_cal)
ctr_reg %>% adjust_numeric_calibration(dummy_reg_cal)
Message
-- Container -------------------------------------------------------------------
Expand All @@ -12,23 +12,23 @@
# errors informatively with bad input

Code
adjust_numeric_calibration(container())
adjust_numeric_calibration(ctr_reg)
Condition
Error in `adjust_numeric_calibration()`:
! `calibrator` is absent but must be supplied.

---

Code
adjust_numeric_calibration(container(), "boop")
adjust_numeric_calibration(ctr_reg, "boop")
Condition
Error in `adjust_numeric_calibration()`:
! `calibrator` should be a <cal_regression> object (`?probably::cal_estimate_linear()`), not a string.

---

Code
adjust_numeric_calibration(container(), dummy_cls_cal)
adjust_numeric_calibration(ctr_cls, dummy_cls_cal)
Condition
Error in `adjust_numeric_calibration()`:
! `calibrator` should be a <cal_regression> object (`?probably::cal_estimate_linear()`), not a <cal_binary> object.
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/adjust-numeric-range.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# adjustment printing

Code
container() %>% adjust_numeric_range()
ctr_reg %>% adjust_numeric_range()
Message
-- Container -------------------------------------------------------------------
Expand All @@ -12,7 +12,7 @@
---

Code
container() %>% adjust_numeric_range(hardhat::tune())
ctr_reg %>% adjust_numeric_range(hardhat::tune())
Message
-- Container -------------------------------------------------------------------
Expand All @@ -23,7 +23,7 @@
---

Code
container() %>% adjust_numeric_range(-1, hardhat::tune())
ctr_reg %>% adjust_numeric_range(-1, hardhat::tune())
Message
-- Container -------------------------------------------------------------------
Expand All @@ -34,7 +34,7 @@
---

Code
container() %>% adjust_numeric_range(hardhat::tune(), 1)
ctr_reg %>% adjust_numeric_range(hardhat::tune(), 1)
Message
-- Container -------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/adjust-predictions-custom.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# adjustment printing

Code
container() %>% adjust_predictions_custom()
ctr_cls %>% adjust_predictions_custom()
Message
-- Container -------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/adjust-probability-calibration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# adjustment printing

Code
container() %>% adjust_probability_calibration(dummy_cls_cal)
ctr_cls %>% adjust_probability_calibration(dummy_cls_cal)
Message
-- Container -------------------------------------------------------------------
Expand All @@ -12,23 +12,23 @@
# errors informatively with bad input

Code
adjust_probability_calibration(container())
adjust_probability_calibration(ctr_cls)
Condition
Error in `adjust_probability_calibration()`:
! `calibrator` is absent but must be supplied.

---

Code
adjust_probability_calibration(container(), "boop")
adjust_probability_calibration(ctr_cls, "boop")
Condition
Error in `adjust_probability_calibration()`:
! `calibrator` should be a <cal_binary> or <cal_multinomial> object (`?probably::cal_estimate_logistic()`), not a string.

---

Code
adjust_probability_calibration(container(), dummy_reg_cal)
adjust_probability_calibration(ctr_cls, dummy_reg_cal)
Condition
Error in `adjust_probability_calibration()`:
! `calibrator` should be a <cal_binary> or <cal_multinomial> object (`?probably::cal_estimate_logistic()`), not a <cal_regression> object.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/adjust-probability-threshold.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# adjustment printing

Code
container() %>% adjust_probability_threshold()
ctr_cls %>% adjust_probability_threshold()
Message
-- Container -------------------------------------------------------------------
Expand All @@ -12,7 +12,7 @@
---

Code
container() %>% adjust_probability_threshold(hardhat::tune())
ctr_cls %>% adjust_probability_threshold(hardhat::tune())
Message
-- Container -------------------------------------------------------------------
Expand Down
11 changes: 6 additions & 5 deletions tests/testthat/_snaps/container.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# container printing

Code
container()
ctr_cls
Message
-- Container -------------------------------------------------------------------
Expand All @@ -10,7 +10,7 @@
---

Code
container(type = "binary")
container(mode = "classification", type = "binary")
Message
-- Container -------------------------------------------------------------------
Expand All @@ -19,7 +19,8 @@
---

Code
container(type = "binary") %>% adjust_probability_threshold(0.2)
container(mode = "classification", type = "binary") %>%
adjust_probability_threshold(0.2)
Message
-- Container -------------------------------------------------------------------
Expand All @@ -30,8 +31,8 @@
---

Code
container(type = "binary") %>% adjust_probability_threshold(0.2) %>%
adjust_equivocal_zone()
container(mode = "classification", type = "binary") %>%
adjust_probability_threshold(0.2) %>% adjust_equivocal_zone()
Message
-- Container -------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/helper-objects.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ctr_cls <- container(mode = "classification")
ctr_reg <- container(mode = "classification")
4 changes: 2 additions & 2 deletions tests/testthat/test-adjust-equivocal-zone.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("adjustment printing", {
expect_snapshot(container() %>% adjust_equivocal_zone())
expect_snapshot(container() %>% adjust_equivocal_zone(hardhat::tune()))
expect_snapshot(ctr_cls %>% adjust_equivocal_zone())
expect_snapshot(ctr_cls %>% adjust_equivocal_zone(hardhat::tune()))
})
11 changes: 4 additions & 7 deletions tests/testthat/test-adjust-numeric-calibration.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
test_that("adjustment printing", {
dummy_reg_cal <- structure(list(), class = "cal_regression")
expect_snapshot(container() %>% adjust_numeric_calibration(dummy_reg_cal))
expect_snapshot(ctr_reg %>% adjust_numeric_calibration(dummy_reg_cal))
})

test_that("errors informatively with bad input", {
# check for `adjust_numeric_calibration(container)` is in `utils.R` tests

expect_snapshot(error = TRUE, adjust_numeric_calibration(container()))
expect_snapshot(error = TRUE, adjust_numeric_calibration(container(), "boop"))
expect_snapshot(error = TRUE, adjust_numeric_calibration(ctr_reg))
expect_snapshot(error = TRUE, adjust_numeric_calibration(ctr_reg, "boop"))
dummy_cls_cal <- structure(list(), class = "cal_binary")
expect_snapshot(
error = TRUE,
adjust_numeric_calibration(container(), dummy_cls_cal)
)
expect_snapshot(error = TRUE, adjust_numeric_calibration(ctr_cls, dummy_cls_cal))
})
8 changes: 4 additions & 4 deletions tests/testthat/test-adjust-numeric-range.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("adjustment printing", {
expect_snapshot(container() %>% adjust_numeric_range())
expect_snapshot(container() %>% adjust_numeric_range(hardhat::tune()))
expect_snapshot(container() %>% adjust_numeric_range(-1, hardhat::tune()))
expect_snapshot(container() %>% adjust_numeric_range(hardhat::tune(), 1))
expect_snapshot(ctr_reg %>% adjust_numeric_range())
expect_snapshot(ctr_reg %>% adjust_numeric_range(hardhat::tune()))
expect_snapshot(ctr_reg %>% adjust_numeric_range(-1, hardhat::tune()))
expect_snapshot(ctr_reg %>% adjust_numeric_range(hardhat::tune(), 1))
})

2 changes: 1 addition & 1 deletion tests/testthat/test-adjust-predictions-custom.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test_that("adjustment printing", {
expect_snapshot(container() %>% adjust_predictions_custom())
expect_snapshot(ctr_cls %>% adjust_predictions_custom())
})
8 changes: 4 additions & 4 deletions tests/testthat/test-adjust-probability-calibration.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
test_that("adjustment printing", {
dummy_cls_cal <- structure(list(), class = "cal_binary")
expect_snapshot(container() %>% adjust_probability_calibration(dummy_cls_cal))
expect_snapshot(ctr_cls %>% adjust_probability_calibration(dummy_cls_cal))
})

test_that("errors informatively with bad input", {
# check for `adjust_probably_calibration(container)` is in `utils.R` tests

expect_snapshot(error = TRUE, adjust_probability_calibration(container()))
expect_snapshot(error = TRUE, adjust_probability_calibration(container(), "boop"))
expect_snapshot(error = TRUE, adjust_probability_calibration(ctr_cls))
expect_snapshot(error = TRUE, adjust_probability_calibration(ctr_cls, "boop"))
dummy_reg_cal <- structure(list(), class = "cal_regression")
expect_snapshot(
error = TRUE,
adjust_probability_calibration(container(), dummy_reg_cal)
adjust_probability_calibration(ctr_cls, dummy_reg_cal)
)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-adjust-probability-threshold.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("adjustment printing", {
expect_snapshot(container() %>% adjust_probability_threshold())
expect_snapshot(container() %>% adjust_probability_threshold(hardhat::tune()))
expect_snapshot(ctr_cls %>% adjust_probability_threshold())
expect_snapshot(ctr_cls %>% adjust_probability_threshold(hardhat::tune()))
})
9 changes: 5 additions & 4 deletions tests/testthat/test-container.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
test_that("container printing", {
expect_snapshot(container())
expect_snapshot(container(type = "binary"))
expect_snapshot(ctr_cls)
expect_snapshot(container(mode = "classification", type = "binary"))
expect_snapshot(
container(type = "binary") %>% adjust_probability_threshold(.2)
container(mode = "classification", type = "binary") %>%
adjust_probability_threshold(.2)
)
expect_snapshot(
container(type = "binary") %>%
container(mode = "classification", type = "binary") %>%
adjust_probability_threshold(.2) %>%
adjust_equivocal_zone()
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("check_container raises informative error", {
expect_snapshot(error = TRUE, adjust_probability_threshold("boop"))
expect_no_condition(container() %>% adjust_probability_threshold(.5))
expect_no_condition(ctr_cls %>% adjust_probability_threshold(.5))
})

0 comments on commit 917196f

Please sign in to comment.