2 title: morpheus...........
10 ```{r setup, results="hide", include=FALSE}
11 knitr::opts_chunk$set(echo = TRUE, include = TRUE,
12 cache = TRUE, comment="", cache.lazy = FALSE,
13 out.width = "100%", fig.align = "center")
16 0) Tell that we try to learn classification parameters in a non-EM way, using algebric manipulations.
18 2) Algorithm (as in article)
19 3) Experiments: show package usage
23 ```{r, results="show", include=TRUE, echo=TRUE}
24 library(Rmixmod) #to get clustering probability matrix
26 library(FactoMineR) #for PCA
28 plotPCA <- function(prob)
30 par(mfrow=c(2,2), mar=c(4,4,2,2), mgp=c(2,1,0))
31 partition <- apply(prob, 1, which.max)
34 palette <- rainbow(K, s=.5)
35 cols <- palette[partition]
36 tmp <- PCA(rbind(prob, diag(K)), ind.sup=(n+1):(n+K), scale.unit=F, graph=F)
37 scores <- tmp$ind$coord[,1:3] #samples coords, by rows
38 ctrs <- tmp$ind.sup$coord #projections of indicator vectors (by cols)
47 plot(absc, ords, col=c(cols,rep(colors()[215],K),rep(1,K)),
48 pch=c(rep("o",n),rep(as.character(1:K),2)),
49 xlim=xrange, ylim=yrange,
50 xlab=paste0("Dim ", i, " (", round(tmp$eig[i,2],2), "%)"),
51 ylab=paste0("Dim ", j, " (", round(tmp$eig[j,2],2), "%)"))
52 ctrsavg <- t(apply(as.matrix(palette), 1,
53 function(cl) c(mean(absc[cols==cl]), mean(ords[cols==cl]))))
54 text(ctrsavg[,1], ctrsavg[,2], as.character(1:K), col=colors()[215])
55 text(ctrs[,i], ctrs[,j], as.character(1:K), col=1)
56 title(paste0("PCA ", i, "-", j, " / K=",K))
60 plot(0, xaxt="n", yaxt="n", xlab="", ylab="", col="white", bty="n")
63 plotClvz <- function(xem, alt=FALSE)
65 par(mfrow=c(2,2), mar=c(4,4,2,2), mgp=c(2,1,0))
67 resvisu <- clusvis(log(xem@bestResult@proba), xem@bestResult@parameters@proportions)
69 resvisu <- clusvisMixmod(xem)
71 plotDensityClusVisu(resvisu, positionlegend=NULL)
72 plotDensityClusVisu(resvisu, add.obs=TRUE, positionlegend=NULL)
74 plot(0, xaxt="n", yaxt="n", xlab="", ylab="", col="white", bty="n")
75 plot(0, xaxt="n", yaxt="n", xlab="", ylab="", col="white", bty="n")
78 grlplot <- function(x, K, alt=FALSE) #x: data, K: nb classes
80 xem <- mixmodCluster(x, K, strategy=mixmodStrategy(nbTryInInit=500,nbTry=25))
81 plotPCA(xem@results[[1]]@proba)
88 ```{r, results="show", include=TRUE, echo=TRUE}
90 x <- iris[,-5] #remove class info
93 print(paste("Resultats en", i, "classes"))
98 ### finance dataset (from Rmixmod package)
100 #This dataset has two categorical attributes (the year and financial status), and four continuous ones.
102 #Warnings, some probabilities of classification are exactly equal to zero then we cannot use ClusVis
104 #```{r, results="show", include=TRUE, echo=TRUE}
109 # print(paste("Resultats en", i, "classes"))
110 # grlplot(x, i, TRUE)
114 ### "Cathy dataset" (12 clusters)
116 #Warnings, some probabilities of classification are exactly equal to zero then we cannot use ClusVis
118 #```{r, results="hide", include=TRUE, echo=TRUE}
119 #cathy12 <- as.matrix(read.table("data/probapostCatdbBlocAtrazine-K12.txt"))
120 #resvisu <- clusvis(log(cathy12), prop = colMeans(cathy12))
121 #par(mfrow=c(2,2), mar=c(4,4,2,2), mgp=c(2,1,0))
122 #plotDensityClusVisu(resvisu, positionlegend = NULL)
123 #plotDensityClusVisu(resvisu, add.obs = TRUE, positionlegend = NULL)
127 ### Pima indian diabete
129 #[Source.](https://gist.github.com/ktisha/c21e73a1bd1700294ef790c56c8aec1f)
131 #```{r, results="show", include=TRUE, echo=TRUE}
132 #load("data/pimaData.rda")
135 # print(paste("Resultats en", i, "classes"))
142 #[Source.](http://archive.ics.uci.edu/ml/datasets/breast+cancer+wisconsin+\%28diagnostic\%29)
144 #```{r, results="show", include=TRUE, echo=TRUE}
145 #load("data/wdbc.rda")
148 # print(paste("Resultats en", i, "classes"))
155 #```{r, results="show", include=TRUE, echo=TRUE}
156 #load("data/house-votes.rda")
159 # print(paste("Resultats en", i, "classes"))