R/class_check.R

Defines functions class_check

Documented in class_check

class_check <- function(pred, truth) {
  tb <- table(pred, truth)
  attr(tb, "overall") <- sum(diag(tb)) / sum(tb)
  attr(tb, "recall") <- diag(apply(tb, 1, function(xx) xx / sum(xx)))
  attr(tb, "precision") <- diag(apply(tb, 2, function(xx) xx / sum(xx)))
  attr(tb, "f1-score") <- 1 /
    (0.5 / attr(tb, "recall") + 0.5 / attr(tb, "precision"))
  tb <- unclass(tb)
  class(tb) <- "checkwise"
  return(tb)
}

Try the HRTnomaly package in your browser

Any scripts or data that you put into this service are public.

HRTnomaly documentation built on April 3, 2025, 6:17 p.m.