tests/testthat/test-fair-equal_opportunity.R

test_that("result matches reference implementation (fairlearn)", {
  data("hpc_cv")
  py_res <- read_pydata("py-equal_opportunity")

  hpc_cv$obs_vf = as.factor(hpc_cv$obs == "VF")
  hpc_cv$pred_vf = as.factor(hpc_cv$pred == "VF")
  hpc_cv$case_weights <- read_weights_hpc_cv()

  eo <- equal_opportunity(Resample)

  expect_equal(
    eo(hpc_cv, truth = obs_vf, estimate = pred_vf, event_level = "second")$.estimate,
    py_res$binary
  )

  expect_equal(
    eo(hpc_cv, truth = obs_vf, estimate = pred_vf,
       event_level = "second", case_weights = case_weights)$.estimate,
    py_res$weighted
  )
})

Try the yardstick package in your browser

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

yardstick documentation built on June 22, 2024, 7:07 p.m.