K-Medoids在处理异常值方面真的比K-Means更好吗? (示例显示相反)

时间:2015-11-23 04:20:27

标签: r cluster-analysis partitioning k-means

K-Medoids K-Means 是两种流行的分区聚类方法。我的研究表明,当存在异常值时,K-Medoids在聚类数据方面更胜一筹(source)。这是因为它选择数据点作为聚类中心(并使用曼哈顿距离),而K-Means选择任何最小化平方和的中心,因此它更受异常值的影响。

这是有道理的,但是当我使用这些方法对组成数据进行简单测试时,并不表示使用Medoids更好地处理异常值,事实上它有时候更糟 。我的问题是:在下面的测试中哪里出错了?也许我对这些方法有一些基本的误解。

演示:(有关图片,请参阅here) 首先,一些数据(名为'comp')构成了3个明显的聚类

x <- c(2, 3, 2.4, 1.9, 1.6, 2.3, 1.8, 5, 6, 5, 5.8, 6.1, 5.5, 7.2, 7.5, 8, 7.2, 7.8, 7.3, 6.4)
y <- c(3, 2, 3.1, 2.6, 2.7, 2.9, 2.5, 7, 7, 6.5, 6.4, 6.9, 6.5, 7.5, 7.25, 7, 7.8, 7.5, 8.1, 7)

data.frame(x,y) -> comp

library(ggplot2)
ggplot(comp, aes(x, y)) + geom_point(alpha=.5, size=3, pch = 16)

enter image description here

它与'vegclust'软件包集群在一起,可以同时使用K-Means和K-Medoids。

library(vegclust)
k <- vegclust(x=comp, mobileCenters=3, method="KM", nstart=100, iter.max=1000) #K-Means
k <- vegclust(x=comp, mobileCenters=3, method="KMdd", nstart=100, iter.max=1000) #K-Medoids

制作散点图时,K-Means和K-Medoids都会获得3个明显的聚类。

color <- k$memb[,1]+k$memb[,2]*2+k$memb[,3]*3 # Making the different clusters have different colors

# K-Means scatterplot
ggplot(comp, aes(x, y)) + geom_point(alpha=.5, color=color, pch = 16, size=3)

# K-Medoids scatterplot
ggplot(comp, aes(x, y)) + geom_point(alpha=.5, color=color, size=3, pch = 16)

See *figure 2* in the link

现在增加了异常值:

comp[21,1] <- 3
comp[21,2] <- 7.5

此异常值将蓝色群集的中心移动到图表的左侧。

因此,在新数据上使用K-Medoids时,蓝色群集的最右侧点将被中断并加入红色群集。

See *figure 3* in the link

有趣的是,K-means实际上生成了更好(更直观)的聚类,新数据偶尔取决于随机初始聚类中心(您可能需要多次运行以获得正确的聚类),而K-Medoids总是生成错误的集群。

See *figure 4* in the link

从这个例子中可以看出,K-Means实际上更好地处理异常值而不是K-Medoids(相同的数据,相同的包等)。我在测试中做错了什么或误解了这些方法是如何工作的?

0 个答案:

没有答案