-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclassification_performance.R
79 lines (63 loc) · 1.65 KB
/
classification_performance.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# script start;
# 1) prelims
# 1.1) clear environment
# and garbage collection
rm(list = ls()); gc();
# 1.2) load DT list
DT <- SLmetrics:::DT
# 2) conduct classification
# tests on 2 x 2 confusion matrix
# 2.1) define test parameters
# that are common
k <- 2 # classes
N <- seq(2e3, by = 2e3, length.out = 50) # sample size
# 2.2) conduct test by
# sample size
results <- data.table::rbindlist(
lapply(
X = N, function(n) {
# 0) garbage collection
invisible(gc())
# 1) generate actual
# and predicted classes
set.seed(1903)
actual <- factor(sample(letters[1:k], size = n, replace = TRUE))
predicted <- factor(sample(letters[1:k], size = n, replace = TRUE))
# 2) conduct tests with
# microbenchmark
data.table::as.data.table(
microbenchmark::microbenchmark(
`{SLmetrics}` = SLmetrics::cmatrix(actual, predicted),
`{yardstick}` = yardstick::conf_mat(table(actual, predicted)),
`{MLmetrics}` = MLmetrics::ConfusionMatrix(predicted, actual),
`{mlr3measures}` = mlr3measures::confusion_matrix(predicted, actual, positive = "a"),
times = 1000
)
)[
,
.(
sample_size = n,
median = median(
time
),
measure = "Confusion Matrix"
)
,
by = .(
expr
)
]
}
)
)
# 3) store data in
# DT in speed
DT$speed$confusion_matrix <- results
# 3.1) write back
# to DT
usethis::use_data(
DT,
internal = TRUE,
overwrite = TRUE
)
# script end;