make_conf_mat <- function(col1, col2) {
confusion <- df_wide |>
select(matches(glue("{col1}|{col2}"))) |>
rename(
label = !!rlang::sym(col1),
prediction = !!rlang::sym(col2)
) |>
group_by(label, prediction) |>
tally() |>
group_by(label) |>
mutate(pct = n / sum(n))
return(confusion)
}
images <- "images"
labels <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L") |> map(~ str_c("<img src=", here(images, str_c("tangram_", ., ".png")), " width='20'/>"))
label <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L")
plot_conf_mat <- function(confusion, col1, col2) {
self <- confusion |>
filter(label == prediction) |>
select(label, self = pct)
corr_order <- tibble(label, labels) |>
left_join(self) |>
arrange(self)
self_2 <- confusion |>
ungroup() |>
filter(label == prediction) |>
select(prediction, self_2 = pct)
p <- confusion |>
left_join(self) |>
left_join(self_2) |>
ggplot(aes(x = reorder(label, self, FUN = mean), y = reorder(prediction, self_2, FUN = mean), fill = pct)) +
geom_tile() +
scale_fill_gradient(low = "white", high = "blue") +
scale_x_discrete(name = col1, labels = corr_order$labels) +
scale_y_discrete(name = col2, labels = corr_order$labels) +
theme(axis.text = element_markdown(color = "black", size = 11))+labs(title="Fine tuned")
return(p)
}
compute_agreement <- function(col1, col2) {
n_agreements <- df_wide |>
filter(!!rlang::sym(col1) == !!rlang::sym(col2)) |>
nrow()
return(n_agreements / nrow(df_wide))
}