This script shows how to read a Channel Binary Entropy Triangle (CBET) using different confusion matrices from (Valverde-Albacete & Peláez-Moreno, 2010).
Some top level switches and options gathered in one place.
debugLevel <- 0 # Debug level 0-non-existent, 1-minimal, the greater the more verbose.
fancy <- TRUE # set this for nicer on-screen visualization.
#fancy <- FALSE # Set this for either printing matter or more austere plots.
getPlot <- TRUE # Flag to obtain plots for publication.
getPlot <- FALSE #Comment to get .jpeg files rather than plots of ets.
knitr::opts_chunk$set(comment=NA, fig.width=6, fig.height=4)
if (getPlot)
knitr::opts_chunk$set(dev = 'pdf') # plots in pdf, better for publication
mats <- list(
a = c(15, 0, 0, 0, 15, 0, 5, 5, 20),
b = c(16, 2, 1, 2, 16, 1, 2, 2, 18),
c = c(1,0,1,0,1,1,4,4,48),
d = c(15,0,0,0,18,0,0,0,27),
e = c(1,0,0,0,2,0,0,0,57),
f = c(0,0,0,0,0,0,5,5,50)
)
as.atable <- function(m){matrix(m, nrow=3,ncol=3)}
cm <- lapply(mats,as.atable)
cmNames <- names(mats)
cm
$a
[,1] [,2] [,3]
[1,] 15 0 5
[2,] 0 15 5
[3,] 0 0 20
$b
[,1] [,2] [,3]
[1,] 16 2 2
[2,] 2 16 2
[3,] 1 1 18
$c
[,1] [,2] [,3]
[1,] 1 0 4
[2,] 0 1 4
[3,] 1 1 48
$d
[,1] [,2] [,3]
[1,] 15 0 0
[2,] 0 18 0
[3,] 0 0 27
$e
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 2 0
[3,] 0 0 57
$f
[,1] [,2] [,3]
[1,] 0 0 5
[2,] 0 0 5
[3,] 0 0 50
etdf <- data.frame()
for (i in 1:length(cmNames)) {
etdf <- rbind(etdf,
cbind(name=cmNames[[i]], jentropies(as.table(cm[[i]])))
)
}
confusion_cbet <-
ggmetern(etdf %>% filter(type == "XY"), fancy) +
geom_point(aes(shape=name), size=3, color="blue") +
labs(shape="Confusion Matrix") +
theme(legend.key=element_blank())
confusion_cbet
if (getPlot){
dev.off()#Necessary to do the textual plot.
ggsave(stringr::str_interp("confusion_matrices_CBET_PRL10_in_R.jpeg"),
plot=confusion_cbet)
}
The analysis of the classifiers generating the matrices is the following: 1. That generating a is an excellent classifier, transferring a lot of information
confusion_split_cbet <-
ggmetern(etdf, fancy) %+%
geom_point(aes(shape=type),
size=3,
color="blue") +
scale_shape_manual(values=c("X"=4, "Y"=1, "XY"=20)) +
labs(shape="Split Confusion Matrix") +
theme(legend.key=element_blank())
confusion_split_cbet <-
confusion_split_cbet +
geom_text(data=etdf %>% filter(type == "XY"), aes(label=name),
color="blue",size=4, vjust=2, hjust=1)
confusion_split_cbet
if (getPlot){
dev.off()#Necessary to do the textual plot.
ggsave(stringr::str_interp("confusion_matrices_split_CBET_PRL10_in_R.jpeg"),
plot=confusion_split_cbet)
}
sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.5
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bindrcpp_0.2.2 entropies_0.9.1 forcats_0.3.0 stringr_1.3.1
[5] dplyr_0.7.6 purrr_0.2.5 readr_1.1.1 tidyr_0.8.1
[9] tibble_1.4.2 ggplot2_2.2.1 tidyverse_1.2.1
loaded via a namespace (and not attached):
[1] nlme_3.1-137 lubridate_1.7.4 dimRed_0.1.0
[4] httr_1.3.1 rprojroot_1.3-2 latex2exp_0.4.0
[7] tensorA_0.36 tools_3.5.0 backports_1.1.2
[10] R6_2.2.2 rpart_4.1-13 lazyeval_0.2.1
[13] colorspace_1.3-2 nnet_7.3-12 withr_2.1.2
[16] tidyselect_0.2.4 gridExtra_2.3 mnormt_1.5-5
[19] bayesm_3.1-0.1 compiler_3.5.0 compositions_1.40-2
[22] cli_1.0.0 rvest_0.3.2 xml2_1.2.0
[25] labeling_0.3 entropy_1.2.1 scales_0.5.0
[28] sfsmisc_1.1-2 DEoptimR_1.0-8 psych_1.8.4
[31] robustbase_0.93-1 digest_0.6.15 foreign_0.8-70
[34] rmarkdown_1.10 pkgconfig_2.0.1 htmltools_0.3.6
[37] rlang_0.2.1 readxl_1.1.0 ddalpha_1.3.4
[40] rstudioapi_0.7 bindr_0.1.1 energy_1.7-4
[43] jsonlite_1.5 ModelMetrics_1.1.0 magrittr_1.5
[46] Matrix_1.2-14 Rcpp_0.12.17 munsell_0.5.0
[49] abind_1.4-5 proto_1.0.0 infotheo_1.2.0
[52] stringi_1.2.3 yaml_2.1.19 MASS_7.3-49
[55] plyr_1.8.4 recipes_0.1.3 grid_3.5.0
[58] pls_2.6-0 parallel_3.5.0 crayon_1.3.4
[61] lattice_0.20-35 haven_1.1.2 splines_3.5.0
[64] hms_0.4.2 knitr_1.20 pillar_1.2.3
[67] boot_1.3-20 stats4_3.5.0 reshape2_1.4.3
[70] codetools_0.2-15 CVST_0.2-2 magic_1.5-8
[73] glue_1.2.0 evaluate_0.10.1 modelr_0.1.2
[76] foreach_1.4.4 cellranger_1.1.0 gtable_0.2.0
[79] kernlab_0.9-26 assertthat_0.2.0 DRR_0.0.3
[82] gower_0.1.2 prodlim_2018.04.18 broom_0.4.5
[85] class_7.3-14 survival_2.41-3 geometry_0.3-6
[88] timeDate_3043.102 RcppRoll_0.3.0 iterators_1.0.9
[91] ggtern_2.2.1 lava_1.6.2 caret_6.0-80
[94] ipred_0.9-6