模型聚类
- 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)
参考资料: