tidymodels / yardstick
Showing 2 of 4 files from the diff.

@@ -154,41 +154,28 @@
Loading
154 154
}
155 155
156 156
roc_auc_binary <- function(truth, estimate, event_level, options) {
157 -
  lvl_values <- levels(truth)
157 +
  lvls <- levels(truth)
158 158
159 159
  if (is_event_first(event_level)) {
160 -
    lvl <- rev(lvl_values)
161 -
  } else {
162 -
    lvl <- lvl_values
160 +
    lvls <- rev(lvls)
163 161
  }
164 162
165 -
  control <- lvl[[1]]
166 -
  event <- lvl[[2]]
163 +
  control <- lvls[[1]]
164 +
  event <- lvls[[2]]
167 165
168 -
  # `NA` values have already been removed by `metric_vec_template()`
169 -
  n_control <- sum(truth == control)
170 -
  n_event <- sum(truth == event)
171 -
172 -
  if (n_control == 0L) {
173 -
    rlang::warn(paste0(
174 -
      "No control observations were detected in `truth` ",
175 -
      "with control level '", control, "'"
176 -
    ))
166 +
  if (compute_n_occurrences(truth, control) == 0L) {
167 +
    warn_roc_truth_no_control(control)
177 168
    return(NA_real_)
178 169
  }
179 -
180 -
  if (n_event == 0L) {
181 -
    rlang::warn(paste0(
182 -
      "No event observations were detected in `truth` ",
183 -
      "with event level '", event, "'"
184 -
    ))
170 +
  if (compute_n_occurrences(truth, event) == 0L) {
171 +
    warn_roc_truth_no_event(event)
185 172
    return(NA_real_)
186 173
  }
187 174
188 175
  args <- quos(
189 176
    response = truth,
190 177
    predictor = estimate,
191 -
    levels = lvl,
178 +
    levels = lvls,
192 179
    quiet = TRUE,
193 180
    direction = "<"
194 181
  )
@@ -288,6 +275,53 @@
Loading
288 275
  auc_val
289 276
}
290 277
278 +
# ------------------------------------------------------------------------------
279 +
280 +
compute_n_occurrences <- function(x, what) {
281 +
  # `NA` values have already been removed by `metric_vec_template()`
282 +
  sum(x == what)
283 +
}
284 +
285 +
msg_roc_truth_no_control <- function(control) {
286 +
  paste0(
287 +
    "No control observations were detected in `truth` ",
288 +
    "with control level '", control, "'."
289 +
  )
290 +
}
291 +
warn_roc_truth_no_control <- function(control) {
292 +
  rlang::warn(
293 +
    msg_roc_truth_no_control(control),
294 +
    class = "yardstick_warning_roc_truth_no_control"
295 +
  )
296 +
}
297 +
stop_roc_truth_no_control <- function(control) {
298 +
  rlang::abort(
299 +
    msg_roc_truth_no_control(control),
300 +
    class = "yardstick_error_roc_truth_no_control"
301 +
  )
302 +
}
303 +
304 +
msg_roc_truth_no_event <- function(event) {
305 +
  paste0(
306 +
    "No event observations were detected in `truth` ",
307 +
    "with event level '", event, "'."
308 +
  )
309 +
}
310 +
warn_roc_truth_no_event <- function(event) {
311 +
  rlang::warn(
312 +
    msg_roc_truth_no_event(event),
313 +
    class = "yardstick_warning_roc_truth_no_event"
314 +
  )
315 +
}
316 +
stop_roc_truth_no_event <- function(event) {
317 +
  rlang::abort(
318 +
    msg_roc_truth_no_event(event),
319 +
    class = "yardstick_error_roc_truth_no_event"
320 +
  )
321 +
}
322 +
323 +
# ------------------------------------------------------------------------------
324 +
291 325
single_quote <- function(x) {
292 326
  encodeString(x, quote = "'", na.encode = FALSE)
293 327
}

@@ -158,6 +158,16 @@
Loading
158 158
    lvls <- rev(lvls)
159 159
  }
160 160
161 +
  control <- lvls[[1]]
162 +
  event <- lvls[[2]]
163 +
164 +
  if (compute_n_occurrences(truth, control) == 0L) {
165 +
    stop_roc_truth_no_control(control)
166 +
  }
167 +
  if (compute_n_occurrences(truth, event) == 0L) {
168 +
    stop_roc_truth_no_event(event)
169 +
  }
170 +
161 171
  # working on a better way of doing this
162 172
  options$response <- truth
163 173
  options$predictor <- estimate
Files Coverage
R 96.66%
src 100.00%
Project Totals (55 files) 96.78%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
        informational: true
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
14
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading