|
a |
|
b/R/J48DTeval.R |
|
|
1 |
#' @title Evaluating the performance of the J48 decision tree. |
|
|
2 |
#' @description This function evaluates the performance of the generated trees |
|
|
3 |
#' for error estimation by ten-fold cross validation assessment. |
|
|
4 |
#' @export |
|
|
5 |
#' @param data The resulted data from running the function J48DT. |
|
|
6 |
#' @param num.folds A numeric value of the number of folds for the cross |
|
|
7 |
#' validation assessment. Default is 10. |
|
|
8 |
#' @param First A string vector showing the first target cluster. Default is |
|
|
9 |
#' "CL1" |
|
|
10 |
#' @param Second A string vector showing the second target cluster. Default is |
|
|
11 |
#' "CL2" |
|
|
12 |
#' @param quiet If `TRUE`, suppresses intermediary output |
|
|
13 |
#' @importFrom stats predict |
|
|
14 |
#' @return Statistics about the J48 model |
|
|
15 |
J48DTeval <- function( |
|
|
16 |
data, num.folds = 10, First = "CL1", Second = "CL2", quiet = FALSE |
|
|
17 |
) { |
|
|
18 |
exp.imput.df <- as.data.frame(t(data)) |
|
|
19 |
num.instances <- nrow(exp.imput.df) |
|
|
20 |
indices <- 1:num.instances |
|
|
21 |
classVector <- factor(colnames(data)) |
|
|
22 |
cv.segments <- split( |
|
|
23 |
sample(indices), rep(1:num.folds, length = num.instances) |
|
|
24 |
) |
|
|
25 |
j48.performance <- cross.val( |
|
|
26 |
exp.imput.df, classVector, cv.segments, j48.performance, "J48", quiet |
|
|
27 |
) |
|
|
28 |
if (!quiet) print(j48.performance) |
|
|
29 |
|
|
|
30 |
j48.confusion.matrix <- matrix(j48.performance, nrow = 2) |
|
|
31 |
rownames(j48.confusion.matrix) <- c( |
|
|
32 |
paste0("Predicted", First), paste0("Predicted", Second) |
|
|
33 |
) |
|
|
34 |
colnames(j48.confusion.matrix) <- c(First, Second) |
|
|
35 |
if (!quiet) print(j48.confusion.matrix) |
|
|
36 |
j48.sn <- round(SN(j48.confusion.matrix), digits = 2) |
|
|
37 |
j48.sp <- round(SP(j48.confusion.matrix), digits = 2) |
|
|
38 |
j48.acc <- round(ACC(j48.confusion.matrix), digits = 2) |
|
|
39 |
j48.mcc <- round(MCC(j48.confusion.matrix), digits = 2) |
|
|
40 |
|
|
|
41 |
if (!quiet) { |
|
|
42 |
message( |
|
|
43 |
"J48 SN: ", j48.sn, "\n", |
|
|
44 |
"J48 SP: ", j48.sp, "\n", |
|
|
45 |
"J48 ACC: ", j48.acc, "\n", |
|
|
46 |
"J48 MCC: ", j48.mcc, "\n" |
|
|
47 |
) |
|
|
48 |
} |
|
|
49 |
return(j48.performance) |
|
|
50 |
} |