模型聚類
- mclust::Mclust
- RWeka::Cobweb
mclust::Mclust
EM算法也稱為期望最大化算法,在是使用該算法聚類時,將數據集看作一個有隱形變量的概率模型,並實現模型最優化,即獲取與數據本身性質最契合的聚類方式為目的,通過‘反復估計’模型參數找出最優解,同時給出相應的最有類別級數k
所需程序安裝包
install.packages("mclust")
函數示例代碼
> library(mclust) > EM<-Mclust(iris[,-5]) > summary(EM,parameters=T) ---------------------------------------------------- Gaussian finite mixture model fitted by EM algorithm ---------------------------------------------------- Mclust VEV (ellipsoidal, equal shape) model with 2 components: log.likelihood n df BIC ICL -215.726 150 26 -561.7285 -561.7289 Clustering table: 1 2
50 100 Mixing probabilities: 1 2
0.333332 0.666668 Means: [,1] [,2] Sepal.Length 5.0060021 6.261996 Sepal.Width 3.4280046 2.871999 Petal.Length 1.4620006 4.905993 Petal.Width 0.2459998 1.675997
可以看到最優類別級數為2,各類分別含有50,100,
mclust::plot.Mclust(EM,what = "classification")
mclust::plot.Mclust(EM,what = "density")
RWeka::Cobweb
COBWEB是一種流行的簡增量概念聚類算法。它以一個分類樹的形式創建層次聚類,每個節點對應一個概念,包含該概念的一個概率描述,概述被分在該節點下的對象。使得該函數,需要安裝RWeka包,在安裝的過程中,可能出現如下的異常
** R ** inst ** preparing package for lazy loading Error : .onLoad failed in loadNamespace() for 'rJava', details: call: fun(libname, pkgname) error: JAVA_HOME cannot be determined from the Registry ERROR: lazy loading failed for package 'RWeka'
* removing 'C:/Users/zhushy/Documents/R/win-library/3.2/RWeka'
安裝jre, 參考資料: http://blog.csdn.net/afei__/article/details/51464783
RWeka包未安裝成功,示例代碼未驗證,待確認
library(RWeka) dcom=iris[,-5] c1<-Cobweb(dcom) c1 c1$class_ids table(predict(c1),dcom$clas)
參考資料: