K-modes算法 matlab实现
function [ resultLabel ] = Kmodes( k,dataSet) %KMODES Summary of this functio 页
%更新中心点,进展下一次划分,直到目标函数收敛 while(true)
iteratorNum=iteratorNum+1;
newcenter=updataCenters(k,resultLabel,dataS);
for i=1:row
data1=dataS(i,:);
selectCluster=zeros(1,k); for j=1:k
data2=newcenter(j,:);
selectCluster(1,j)=calculateDis(data1,data2);
end
[minx tlabel]=min(selectCluster); resultLabel(i,1)=tlabel; end
objValue=calculateObjectFunction(k,resultLabel,dataS,newcenter);
if((size(objValueVector,2)>0)&&(objValue==objValueVector(1,size(objValueVector,2)))); break; end
objValueVector=[objValueVector objValue]; end
t2=clock;
time=etime(t2,t1)
iterNum=iteratorNum
%计算两个数据之间的相异度
function [dis]=calculateDis(p1,p2) dis=0;
for ii=1:size(p1,2)
if(p1(1,ii)~=p2(1,ii)) dis=dis+1; end end end
%更新中心点 function
[newCenters]=updataCenters(k,resultLabel,data)
newCenters=zeros(k,size(data,2)); for ii=1:k
tempData=[];
for jj=1:size(resultLabel,1)
K-modes算法 matlab实现 来自淘豆网m.daumloan.com转载请标明出处.