
Precision by species and confidence band, and by confidence threshold
Source:R/05_validation_metrics.R
pam_validation_metrics.RdPrecision by species and confidence band, and by confidence threshold
Arguments
- val
Reviewed samples from
pam_validation_import().- pool
Pool of all events from
pam_validation_pool(); its cell sizes weight the threshold estimates, because sampling is stratified.- bands
Confidence band edges used when sampling.
Value
A list:
cells: per species x band:n_pool,n_reviewed,n_correct,n_incorrect,n_unsure,n_judged,precisionand its 95% Wilson interval (unsure verdicts are excluded from precision).thresholds: for each species (and "ALL") and each band edge, the estimated precision of all events at or above that confidence, weighted by band size, pluscoverage(share of those events that sit in bands with at least one judged sample).confusion: counts of predicted species vs the true species entered for incorrect verdicts.
Details
Recall, false negatives and F1 cannot be estimated from reviewing detections alone: they need a set of recordings in which every call has been annotated independently of the detector.
Examples
ex <- pam_example_project()
# the later stages read the master table that the scan builds
res <- suppressMessages(pam_scan_audio(ex$cfg))
new <- suppressMessages(pam_validation_draw(ex$cfg, strategy = "random", n = 8))
val_dir <- file.path(ex$cfg$paths$detections, "run01", "validation")
# normally the review app writes this file; here the verdicts are made up
results <- data.frame(sample_id = new$sample_id,
verdict = rep_len(c("correct", "correct", "incorrect"), nrow(new)),
true_species = NA_character_, note = "", reviewer = "example",
reviewed_at = format(Sys.time()), stringsAsFactors = FALSE)
utils::write.csv(results, file.path(val_dir, "validation_results.csv"), row.names = FALSE)
val <- pam_validation_import(ex$cfg)
pool <- suppressMessages(pam_validation_pool(ex$cfg))
metrics <- pam_validation_metrics(val, pool, bands = unlist(ex$cfg$validation$bands))
as.data.frame(metrics$cells)[, c("scientific_name", "band", "n_pool", "n_reviewed", "precision")]
#> scientific_name band n_pool n_reviewed precision
#> 1 Ducula nicobarica 0.50-0.70 2 0 NA
#> 2 Ducula nicobarica 0.70-1.00 2 1 1.0
#> 3 Gracula religiosa 0.30-0.40 1 1 1.0
#> 4 Gracula religiosa 0.70-1.00 1 1 1.0
#> 5 Psittacula longicauda 0.40-0.50 1 1 0.0
#> 6 Psittacula longicauda 0.50-0.70 2 2 0.5
#> 7 Psittacula longicauda 0.70-1.00 3 2 1.0