【问题标题】:K-means cluster plot [closed]K-means 聚类图
【发布时间】:2013-08-08 03:23:41
【问题描述】:

我有一个 510x6 的数据矩阵,想对此进行 K-means 聚类分析。我在绘制二维中的所有不同集群时遇到问题。不能在二维中绘制 6 个不同的集群吗?

【问题讨论】:

    标签: matlab cluster-analysis k-means


    【解决方案1】:

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

    load fisheriris
    

    然后我们可以将数据分解为六个集群:

    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, :);
    

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

    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')
    

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

    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 函数的事情:

    plotmatrix(meas)
    

    【讨论】:

      猜你喜欢
      • 2015-04-11
      • 2011-08-13
      • 2013-02-14
      • 2018-01-14
      • 2011-04-11
      • 2016-12-16
      • 2011-06-06
      • 2018-02-27
      • 2019-11-25
      相关资源
      最近更新 更多