Title: EM test
Summary: Model based clustering:Expectation Maximization
Using the mclust package, No need to provide number of clusters
Libraries = c("readr", "mclust", "clusteval", "knitr", "rgl")
# Install if not present
for(p in Libraries){
if(!require(p, character.only = TRUE)) { install.packages(p, dependencies = T) }
library(p, character.only = TRUE)
}
data(iris)
Iris_data <- iris[,-5]
Iris_class <- iris[, 5]
iris_BIC <- mclustBIC(Iris_data)
iris_BIC
## Bayesian Information Criterion (BIC):
## EII VII EEI VEI EVI VVI
## 1 -1804.0854 -1804.0854 -1522.1202 -1522.1202 -1522.1202 -1522.1202
## 2 -1123.4117 -1012.2352 -1042.9679 -956.2823 -1007.3082 -857.5515
## 3 -878.7650 -853.8144 -813.0504 -779.1566 -797.8342 -744.6382
## 4 -893.6140 -812.6048 -827.4036 -748.4529 -837.5452 -751.0198
## 5 -782.6441 -742.6083 -741.9185 -688.3463 -766.8158 -711.4502
## 6 -715.7136 -705.7811 -693.7908 -676.1697 -774.0673 -707.2901
## 7 -731.8821 -698.5413 -713.1823 -680.7377 -813.5220 -766.6500
## 8 -725.0805 -701.4806 -691.4133 -679.4640 -740.4068 -764.1969
## 9 -694.5205 -700.0276 -696.2607 -702.0143 -767.8044 -755.8290
## EEE EVE VEE VVE EEV VEV EVV
## 1 -829.9782 -829.9782 -829.9782 -829.9782 -829.9782 -829.9782 -829.9782
## 2 -688.0972 -657.2263 -656.3270 -605.1841 -644.5997 -561.7285 -658.3306
## 3 -632.9647 -666.5491 -605.3982 -636.4259 -644.7810 -562.5522 -656.0359
## 4 -646.0258 -705.5435 -604.8371 -639.7078 -699.8684 -602.0104 -725.2925
## 5 -604.8131 -723.7199 NA -632.2056 -652.2959 -634.2890 NA
## 6 -609.8543 -661.9497 -609.5584 -664.8224 -664.4537 -679.5116 NA
## 7 -632.4947 -699.5102 NA -690.6108 -709.9530 -704.7699 -809.8276
## 8 -639.2640 -700.4277 -654.8237 -709.9392 -735.4463 -712.8788 -831.7520
## 9 -653.0878 -729.6651 NA -734.2997 -758.9348 -748.8237 -882.4391
## VVV
## 1 -829.9782
## 2 -574.0178
## 3 -580.8396
## 4 -630.6000
## 5 -676.6061
## 6 -754.7938
## 7 -806.9277
## 8 -830.6373
## 9 -883.6931
##
## Top 3 models based on the BIC criterion:
## VEV,2 VEV,3 VVV,2
## -561.7285 -562.5522 -574.0178
summary(iris_BIC)
## Best BIC values:
## VEV,2 VEV,3 VVV,2
## BIC -561.7285 -562.5522369 -574.01783
## BIC diff 0.0000 -0.8237748 -12.28937
plot(iris_BIC)
model <- Mclust(Iris_data, x = iris_BIC)
cluster_similarity(model$classification,
Iris_class,
similarity = "rand")
## [1] 0.7762864
Link_EM <- mclustBIC(Iris_data)
plot(Link_EM)
knit_hooks$set(webgl = hook_webgl)
mfrow3d(nr = 1, nc = 2, sharedMouse = T)
plot3d((Iris_data),
col = model$classification,
type = "s",
radius = 0.1,
main = "EM")
Iris_class <- factor(Iris_class)
plot3d((Iris_data),
col = list(setosa = "blue",
versicolor = "red",
virginica = "black"),
type = "s",
radius=0.1,
main="Ground Truth")
rglwidget()
Sys.info()[c(1:3,5)]
## sysname
## "Linux"
## release
## "4.15.0-48-generic"
## version
## "#51~16.04.1-Ubuntu SMP Fri Apr 5 12:01:12 UTC 2019"
## machine
## "x86_64"
sessionInfo()
## R version 3.4.4 (2018-03-15)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Linux Mint 18.3
##
## Matrix products: default
## BLAS: /usr/lib/libblas/libblas.so.3.6.0
## LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] parallel stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] rgl_0.100.19 knitr_1.22 clusteval_0.1 mclust_5.4.3
## [5] doMC_1.3.5 iterators_1.0.10 foreach_1.4.4 readr_1.3.1
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.1 pillar_1.3.1
## [3] compiler_3.4.4 later_0.8.0
## [5] tools_3.4.4 digest_0.6.18
## [7] jsonlite_1.6 evaluate_0.13
## [9] tibble_2.1.1 pkgconfig_2.0.2
## [11] rlang_0.3.4 shiny_1.3.2
## [13] crosstalk_1.0.0 yaml_2.2.0
## [15] mvtnorm_1.0-8 xfun_0.6
## [17] stringr_1.4.0 htmlwidgets_1.3
## [19] hms_0.4.2 webshot_0.5.1
## [21] manipulateWidget_0.10.0 R6_2.4.0
## [23] rmarkdown_1.12 magrittr_1.5
## [25] codetools_0.2-16 promises_1.0.1
## [27] htmltools_0.3.6 mime_0.6
## [29] xtable_1.8-4 httpuv_1.5.1
## [31] miniUI_0.1.1.1 stringi_1.4.3
## [33] crayon_1.3.4
EOF