MATLAB学习(九)系统聚类
>> X=rand(100,2);
>> Y=pdist(X,'euclidean');
>> Z = linkage(Y,'average');
>> dendrogram(Z);
>>
>> X = [randn(100,2)+ones(100,2);randn(100,2)-ones(100,2)];
>> [idx,ctrs] = kmeans(X,2); %分二类,返回类别标号,类心坐标
>> plot(X(idx==1,1),X(idx==1,2),'r.',X(idx==2,1),X(idx==2,2),'b.')
hold on
plot(ctrs(:,1),ctrs(:,2),'kx', ctrs(:,1),ctrs(:,2),'ko')
>>
>> load fisheriris %装入费歇尔的经典花萼尺寸、种类数据
>> SL = meas(:,1);SW=meas(:,2);group = species;
X=meas([4,54,124],1);Y=meas([4,54,124],2);
[C,err,P,logp,coeff] = classify([X Y],[SL SW], group,'linear');
>> nb=NaiveBayes.fit([SL SW], group);
>> cpre=predict(nb,[X,Y])
cpre =
'setosa'
'versicolor'
'versicolor'