模糊聚类c聚类matlab、实例
时间: 2023-11-02 16:52:23 浏览: 100
以下是一个使用 MATLAB 进行模糊C聚类的示例:
```matlab
% 生成一些随机数据
rng default;
X = [randn(100,2)*0.75+ones(100,2);
randn(100,2)*0.5-ones(100,2)];
% 运行模糊 C 均值聚类算法
options = [NaN NaN NaN 0]; % 默认选项
[centers,U] = fcm(X, 2, options);
% 可视化聚类结果
figure;
subplot(1,2,1);
plot(X(:,1), X(:,2), 'o');
title('原始数据');
subplot(1,2,2);
maxU = max(U);
index1 = find(U(1,:) == maxU);
index2 = find(U(2,:) == maxU);
plot(X(index1,1), X(index1,2), 'ro');
hold on;
plot(X(index2,1), X(index2,2), 'go');
plot(centers(:,1), centers(:,2), 'k*', 'MarkerSize', 10);
title('模糊C聚类结果');
% 显示聚类中心和隶属度矩阵
fprintf('聚类中心:\n');
disp(centers);
fprintf('隶属度矩阵:\n');
disp(U);
```
该示例中,我们首先生成了一些随机的二维数据。然后使用 `fcm` 函数执行模糊C均值聚类算法,将数据分为两个聚类簇。最后,我们可视化了原始数据和聚类结果,并显示了聚类中心和隶属度矩阵。
请注意,`fcm` 函数的第一个参数是输入数据矩阵,第二个参数是聚类数目,第三个参数是选项向量。在示例中,我们使用了默认选项,并将聚类数设置为2。你可以根据需要调整这些参数。
阅读全文
相关推荐













