tests/testthat/test_eval_wrappers.R

context("test eval wrappers")

test_eval_frame <- get_test_eval_frame()

test_that("eval_precision_recall works well", {
   compute_prcurve <- wrap_simple_eval(
     simple_eval_fun = aux_compute_prcurve,
     unnest = TRUE)

   actual <- compute_prcurve(test_eval_frame)

   expected <- list(0.993205062959527, structure(list(recall = c(1, 1, 1, 1,
           1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.994285714285714,
           0.984285714285714, 0.974285714285714, 0.964285714285714,
           0.964285714285714, 0.964285714285714, 0.964285714285714,
           0.964285714285714, 0.964285714285714, 0.958571428571429,
           0.948571428571429, 0.938571428571429, 0.928571428571429,
           0.928571428571429, 0.928571428571429, 0.892857142857143,
           0.857142857142857, 0.821428571428571, 0.785714285714286, 0.75,
           0.714285714285714, 0.678571428571429, 0.607142857142857,
           0.571428571428571, 0.535714285714286, 0.5, 0.464285714285714,
           0.428571428571429, 0.392857142857143, 0.357142857142857,
           0.321428571428571, 0.285714285714286, 0.25, 0.214285714285714,
           0.178571428571429, 0.142857142857143, 0.107142857142857,
           0.0714285714285714, 0.0357142857142857, 0), precision = c(0.56,
           0.56, 0.571428571428571, 0.583333333333333, 0.595744680851064,
           0.608695652173913, 0.622222222222222, 0.636363636363636,
           0.651162790697674, 0.666666666666667, 0.682926829268293, 0.7,
           0.717948717948718, 0.736842105263158, 0.756756756756757,
           0.777777777777778, 0.8, 0.823529411764706, 0.848484848484849,
           0.847746650426309, 0.846437346437346, 0.845105328376704, 0.84375,
           0.84375, 0.870967741935484, 0.9, 0.931034482758621,
           0.964285714285714, 0.964080459770115, 0.963715529753266,
           0.963343108504399, 0.962962962962963, 0.962962962962963, 1, 1, 1,
           1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
           1), threshold = c(9.21565787252715e-06, 9.21565787252715e-06,
           2.4073242657244e-05, 0.000129011436572194, 0.00053280840957093,
           0.000538770265615018, 0.000639758616597172, 0.000788622669052344,
           0.00300948259458385, 0.0044987010721369, 0.0070434199588792,
           0.00844619606520535, 0.0141885024034008, 0.0183286180167691,
           0.01941105958721, 0.0415848040205573, 0.0439791657792245,
           0.0527280162900364, 0.0532868779185862, 0.0532868779185862,
           0.0532868779185862, 0.0532868779185862, 0.0532868779185862,
           0.0756030056074748, 0.126946900373167, 0.152015290551632,
           0.229783464562671, 0.272357567187257, 0.272357567187257,
           0.272357567187257, 0.272357567187257, 0.272357567187257,
           0.386460864244664, 0.589599891759606, 0.595950819049829,
           0.654239801213621, 0.698356986076952, 0.850841381303695,
           0.873005323740343, 0.914633610334624, 0.940271807008529,
           0.941314601694413, 0.968327466486679, 0.969969702273045,
           0.98401659934103, 0.992030300926546, 0.995802838907584,
           0.996010274688708, 0.996127172752262, 0.997097442709589,
           0.997911279075184, 0.998899183287407, 0.999355414722397,
           0.999556300422334, 0.999809022841281, 0.999921889400231,
           0.999970427964975, 0.999973132805233, 0.999973132805233)), class =
       "data.frame", row.names = c(NA, -59L)), structure(list(fscore =
         0.964285714285714, recall = 0.964285714285714, precision =
         0.964285714285714, threshold = 0.272357567187257), row.names = c(NA,
       -1L), class = c("tbl_df", "tbl", "data.frame")), structure(list( fscore
       = 0.96551724137931, recall = 1, precision = 0.848484848484849,
       threshold = 0.0532868779185862), row.names = c(NA, -1L), class =
     c("tbl_df", "tbl", "data.frame")))
  expect_equal(expected[[1]], actual$evaluation[[1]],
    tolerance = 1e-4)
  expect_equal(expected[[2]], actual$evaluation[[2]],
    tolerance = 1e-4)
  expect_equal(
    as.numeric(expected[[3]]),
    as.numeric(actual$evaluation[[3]]),
    tolerance = 1e-3
  )
  expect_equal(
    as.numeric(expected[[4]]),
    as.numeric(actual$evaluation[[4]]),
    tolerance = 1e-4
  )
})
signaux-faibles/MLsegmentr documentation built on Aug. 29, 2019, 2:22 p.m.