# NOT RUN {
# Two class
data("two_class_example")
gain_capture(two_class_example, truth, Class1)
# Multiclass
library(dplyr)
data(hpc_cv)
# You can use the col1:colN tidyselect syntax
hpc_cv %>%
filter(Resample == "Fold01") %>%
gain_capture(obs, VF:L)
# Groups are respected
hpc_cv %>%
group_by(Resample) %>%
gain_capture(obs, VF:L)
# Weighted macro averaging
hpc_cv %>%
group_by(Resample) %>%
gain_capture(obs, VF:L, estimator = "macro_weighted")
# Vector version
# Supply a matrix of class probabilities
fold1 <- hpc_cv %>%
filter(Resample == "Fold01")
gain_capture_vec(
truth = fold1$obs,
matrix(
c(fold1$VF, fold1$F, fold1$M, fold1$L),
ncol = 4
)
)
# Visualize gain_capture() --------------------------------------------------
# Visually, this represents the area under the black curve, but above the
# 45 degree line, divided by the area of the shaded triangle.
library(ggplot2)
autoplot(gain_curve(two_class_example, truth, Class1))
# }
Run the code above in your browser using DataLab