K-均值聚类图 [英] K-means cluster plot

查看:140
本文介绍了K-均值聚类图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个510x6的数据矩阵,并希望对此进行K-均值聚类分析.我在二维绘制所有不同的群集时遇到问题.不可能在2维上绘制6个不同的簇吗?

I have a data matrix of 510x6 and want to perform K-means cluster analysis on this. I am having problem in plotting all the different clusters in 2 dimensions. Is it not possible to plot 6 different clusters in 2 dimensions?

推荐答案

让我们首先查看一些150x4的数据,然后尝试将其拆分为6个不同的群集. fisheriris数据集有四列(您有6列),分别对应于萼片长度,萼片宽度,花瓣长度和花瓣宽度,可以像这样加载到MATLAB中:

Let's start by looking at some data which is 150x4 and try and split that into 6 different clusters. The fisheriris dataset has four columns (yours has 6), which correspond to sepal length, sepal width, petal length and petal width and can be loaded into MATLAB like this:

load fisheriris

然后我们可以使用以下方法将数据分为六个集群:

We can then break the data down into six clusters with:

clusters = kmeans(meas, 6);

cluster1 = meas(clusters == 1, :);
cluster2 = meas(clusters == 2, :);
cluster3 = meas(clusters == 3, :);
cluster4 = meas(clusters == 4, :);
cluster5 = meas(clusters == 5, :);
cluster6 = meas(clusters == 6, :);

鉴于每个数据点都有四个信息,为了可视化每个集群,我们需要选择要查看的内容.例如,我可能要查看相对于萼片宽度的萼片长度的簇.这是前两列,我可以通过以下方式看到它们:

Given that we have four pieces of information for each data point, in order to visualise each cluster we need to choose what we want to look at. For example I might want to look at the clusters for sepal length against sepal width. These are the first two columns and I can see them with:

figure
axes

plot(cluster1(:, [1, 2]), '*'); hold all
plot(cluster2(:, [1, 2]), '*')
plot(cluster3(:, [1, 2]), '*')
plot(cluster4(:, [1, 2]), '*')
plot(cluster5(:, [1, 2]), '*')
plot(cluster6(:, [1, 2]), '*')

xlabel('Sepal Length')
ylabel('Sepal Width')

如果我想一次查看列,我们需要增加一个维度:

If I want to look at columns at once, we need to go up a dimension:

figure
axes
hold all

plot3(cluster1(:, 1), cluster1(:, 2), cluster1(:, 3),'*')
plot3(cluster2(:, 1), cluster2(:, 2), cluster2(:, 3),'*')
plot3(cluster3(:, 1), cluster3(:, 2), cluster3(:, 3),'*')
plot3(cluster4(:, 1), cluster4(:, 2), cluster4(:, 3),'*')
plot3(cluster5(:, 1), cluster5(:, 2), cluster5(:, 3),'*')
plot3(cluster6(:, 1), cluster6(:, 2), cluster6(:, 3),'*')

grid on
box on

您的数据具有六个维度,因此,很难从视觉上了解聚类.您可以尝试执行类似于plotmatrix函数的操作:

Your data has six dimensions so it is even harder to get a sense of the clusters visually. You could have a go at doing something similar to the plotmatrix function:

plotmatrix(meas)

这篇关于K-均值聚类图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆