我渴望在尺寸缩小的渔夫虹膜数据中找到k个最近邻居。所以我在Matlab中分别编写了PCA和kNN代码:
对于PCA:
load fisheriris
[pc,score,latent,tsquare] = princomp(meas);
pc,latent
cumsum(latent)./sum(latent); % variance explained by each component
gscatter(score(:,1), score(:,2), species, [], [], [], 'on', 'PC1', 'PC2')
title('Projected Iris data'), grid on
表示kNN
x = meas(:,3:4);
y = [5 1.45;6 2;2.75 .75]; % how do we choose query points?
[n,d]=knnsearch(x,y,'k',10);
gscatter(x(:,1),x(:,2),species)
line(y(:,1),y(:,2),'marker','x','color','k',...
'markersize',10,'linewidth',2,'linestyle','none')
line(x(n,1),x(n,2),'color',[.5 .5 .5],'marker','o',...
'linestyle','none','markersize',10)
set(legend,'location','best')
tabulate(species(n,:))
如何在PCA数据上显示kNN图?
感谢您的支持!