You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MATLAB层次聚类后新数据点的聚类归属判定方法咨询

如何给层次聚类的新数据点分配簇?

我来一步步帮你解决这个问题~你已经用complete linkage(最长距离法)完成了层次聚类,现在要给新数据点[1 0 1]分簇,核心思路就是严格遵循你聚类时用的连接规则,计算新点到每个簇的距离,再选择距离更近的那个簇。

步骤1:提取已有的簇样本

首先把你聚类得到的两个簇的样本单独拎出来:

X = [1 1 1; 2 2 2; 1 1 0; 1 2 2];
c = [1;2;1;2]; % 你的聚类结果

cluster1 = X(c == 1, :); % 簇1:[1 1 1; 1 1 0]
cluster2 = X(c == 2, :); % 簇2:[2 2 2; 1 2 2]

步骤2:计算新点到每个簇的距离(遵循complete linkage规则)

因为你用的是complete连接方式,新点到一个簇的距离定义为新点到该簇内所有样本的最大距离。用MATLAB的pdist2函数计算距离最方便(默认是欧氏距离,和你之前pdist用的一致):

new_point = [1 0 1];

% 计算到簇1的所有距离,取最大值
dist_cluster1 = pdist2(new_point, cluster1);
max_dist1 = max(dist_cluster1); 

% 计算到簇2的所有距离,取最大值
dist_cluster2 = pdist2(new_point, cluster2);
max_dist2 = max(dist_cluster2);

步骤3:判断归属

比较两个最大距离,新点属于距离更小的簇:

if max_dist1 < max_dist2
    assigned_cluster = 1;
else
    assigned_cluster = 2;
end
disp(['新点归属簇#', num2str(assigned_cluster)]);

实际计算结果验证

我们手动算一遍确认:

  • 新点到簇1的两个样本距离分别是1和√2≈1.414,最大距离是1.414
  • 新点到簇2的两个样本距离分别是√6≈2.449和√5≈2.236,最大距离是2.449
    显然1.414 < 2.449,所以新点归属簇#1。

额外提醒

如果你当时用的是其他连接方式(比如single最短距离、average平均距离),就要对应改变距离的计算规则:

  • single:取新点到簇内样本的最小距离
  • average:取新点到簇内样本的平均距离
  • ward:需要计算新点加入后簇的方差变化,选择方差增加最小的簇

内容的提问来源于stack exchange,提问作者Rashid Bagheri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:54:40