|
| 1 | +test_that("basic adjust_equivocal_zone() usage works", { |
| 2 | + skip_if_not_installed("modeldata") |
| 3 | + library(dplyr) |
| 4 | + library(modeldata) |
| 5 | + |
| 6 | + # fitting and predicting happens without raising conditions |
| 7 | + expect_no_condition( |
| 8 | + tlr <- |
| 9 | + tailor() %>% |
| 10 | + adjust_equivocal_zone(value = 1 / 4) |
| 11 | + ) |
| 12 | + |
| 13 | + expect_no_condition( |
| 14 | + tlr_fit <- fit( |
| 15 | + tlr, |
| 16 | + two_class_example, |
| 17 | + outcome = c(truth), |
| 18 | + estimate = c(predicted), |
| 19 | + probabilities = c(Class1, Class2) |
| 20 | + ) |
| 21 | + ) |
| 22 | + |
| 23 | + expect_no_condition( |
| 24 | + tlr_pred <- predict(tlr_fit, two_class_example) |
| 25 | + ) |
| 26 | + |
| 27 | + # classes are as expected |
| 28 | + expect_s3_class(tlr, "tailor") |
| 29 | + expect_s3_class(tlr_fit, "tailor") |
| 30 | + expect_s3_class(tlr_pred, "tbl_df") |
| 31 | + expect_s3_class(tlr_pred$predicted, "class_pred") |
| 32 | + |
| 33 | + # column names are as expected |
| 34 | + expect_equal(colnames(two_class_example), colnames(tlr_pred)) |
| 35 | + |
| 36 | + # prediction classes are as expected |
| 37 | + expect_equal(levels(tlr_pred$predicted), levels(two_class_example$predicted)) |
| 38 | + expect_equal(attr(tlr_pred$predicted, "equivocal"), "[EQ]") |
| 39 | + |
| 40 | + # calculations match those done manually |
| 41 | + tlr_pred_col <- as.character(tlr_pred$predicted) |
| 42 | + manual_pred_col <- ifelse(two_class_example$Class1 > .5, "Class1", "Class2") |
| 43 | + manual_pred_col <- |
| 44 | + ifelse( |
| 45 | + two_class_example$Class1 > .25 & two_class_example$Class1 < .75, |
| 46 | + NA_character_, |
| 47 | + manual_pred_col |
| 48 | + ) |
| 49 | + expect_equal(tlr_pred_col, manual_pred_col) |
| 50 | +}) |
| 51 | + |
| 52 | +# TODO: test sensitivity to function arguments |
| 53 | + |
1 | 54 | test_that("adjustment printing", {
|
2 | 55 | expect_snapshot(tailor() %>% adjust_equivocal_zone())
|
3 | 56 | expect_snapshot(tailor() %>% adjust_equivocal_zone(hardhat::tune()))
|
|
0 commit comments