資源簡介
壓縮包里有三個matlab程序,分別是K-mean聚類、LVQ聚類和混合高斯聚類,數據為兩類二維高斯分布的隨機點。程序展示了三種聚類算法的基本使用方法。算法原理可以參考周志華《機器學習》的第九章聚類。

代碼片段和文件信息
%%聚類算法測試
%%
%%生成數據集
clear
close?all
mu?=?[2?3];
SIGMA?=?[1?0;?0?2];
n1?=?100;
r?=?mvnrnd(muSIGMAn1);
plot(r(:1)r(:2)‘r+‘);
hold?on;
mu?=?[5?6];
SIGMA?=?[?1?0;?0?2];
n2?=?100;
r2?=?mvnrnd(muSIGMAn2);
plot(r2(:1)r2(:2)‘*‘)
title(‘original?data‘)
N?=?n1?+?n2;
data?=?[r;r2];
k?=?randperm(200);
data?=?data(k:);
%%
%%K-mean算法
C?=?2;
nu?=?zeros(C2);
lamda?=?zeros(NC);
for?i?=?1:C
????nu(i:)?=?data(randi(n11):);
end
R?=?100;
while(R)
????for?i?=?1:C
????????lamda(:i)?=?sqrt(sum((data?-?nu(i:)).^22));
????end
????[~?index]?=?min(lamda.‘);
????for?i?=?1:C
????????nu(i:)?=?mean(data(index?==?i:));
????end
????R?=?R?-?1;
end
C1?=?data(index?==?1:);
C2?=?data(index?==?2:);
figure(2)
plot(C1(:1)C1(:2)‘r+‘);
hold?on;
plot(C2(:1)C2(:2)‘*‘)
title(‘k-mean?cluster‘)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????1140??2018-08-17?08:32??LVQ_cluster.m
?????文件????????1741??2018-08-17?09:21??mixture_of_gaussian_cluster.m
?????文件?????????852??2018-08-16?21:18??K_mean_cluster_test.m
評論
共有 條評論