【问题标题】:How can I color-label the cluster data after GMM is fitted?安装 GMM 后如何对集群数据进行颜色标记?
【发布时间】:2019-08-06 09:58:29
【问题描述】:

我正在尝试按照 GMM 对集群数据进行一些标记,但还没有找到方法。

让我解释一下:

我将一些 x,y 数据对放入 X=30000x2 数组中。实际上,该数组包含来自不同来源(已知)的数据,并且每个来源具有相同数量的数据(因此来源 1 有 500 (x,y),来源 2 500 (x,y) 等等,它们都是附加到上面的 X 数组中)。

我已经在 X 上安装了 GMM。聚类结果很好并且符合预期,但是现在数据已经聚类,我希望能够根据它们的初始来源对它们进行颜色编码。

假设我想用黑色显示集群 2 中源 1 的数据点。

这可能吗?

示例: 在原始数组中,我们有三个数据源。源 1 是 1-10000 的数据,源 2 10001-20000 和源 3 20001-30000 的数据。

在 GMM 拟合和聚类之后,我按照图 1 对数据进行了聚类,得到了两个聚类。所有这些中的红色都无关紧要。

我想根据它们的索引和原始数组 X 修改簇 2 中数据点的颜色。 例如,如果一个数据点属于集群 2 (clusteridx=2),那么我想检查它属于哪个源,然后给它着色并相应地标记它。这样您就可以分辨出集群 2 中的数据点来自哪个来源,如第二张图所示。

原始集群

想要的标签

【问题讨论】:

标签: matlab cluster-analysis gmm


【解决方案1】:

您可以添加一个“source_id”列,然后在其上循环绘制。例如:

% setup fake data
source1 = rand(10,2);
source2 = rand(15,2);
source3 = rand(8,2);
% end setup

% append column with source_id (you could do this in a loop if you have many sources)
source1 = [source1, repmat(1, length(source1), 1)];
source2 = [source2, repmat(2, length(source2), 1)];
source3 = [source3, repmat(3, length(source3), 1)];

mytable = array2table([source1; source2; source3]);
mytable.Properties.VariableNames = {'X' 'Y' 'source_id'};

figure
hold on;
for ii = 1:max(mytable.source_id)
    rows = mytable.source_id==ii;
    x = mytable.X(rows);
    y = mytable.Y(rows);
    label = char(strcat('Source ID =', {' '}, num2str(ii)));
    mycolor = rand(1,3); 
    scatter(x,y, 'MarkerEdgeColor', mycolor, 'MarkerFaceColor', mycolor, 'DisplayName', label);
end
set(legend, 'Location', 'best')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 2014-12-11
    • 2021-01-13
    • 1970-01-01
    • 2020-06-27
    • 2018-05-04
    • 1970-01-01
    相关资源
    最近更新 更多