-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaccuracy_assessment.R
29 lines (22 loc) · 1.06 KB
/
accuracy_assessment.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# --------------------------------------------------------------------------------------
# this script calculates the accuracy of mining polygons based on control points -------
library(tidyverse)
library(caret)
library(sf)
# --------------------------------------------------------------------------------------
# get control points from PostGIS database ---------------------------------------------
control_tbl <- sf::st_read("./input/validation_points_v1.gpkg") %>%
sf::st_drop_geometry() %>%
tibble::as_tibble()
# --------------------------------------------------------------------------------------
# calculate accuracy -------------------------------------------------------------------
err <- table(control_tbl) %>%
as.matrix()
# User's accuracy = Sensitivity = Recall (positive class) =
diag(err) / apply(err, 2, sum)
# Producer's accuracy
diag(err) / apply(err, 1, sum)
# Overall accuracy
sum(diag(err)) / sum(apply(err, 1, sum))
# All accuracy metrics
caret::confusionMatrix(data = control_tbl$MAPPED, reference = control_tbl$REFERENCE, mode = "everything")