资源简介
这是基本的k近邻的matlab的代码,大家可以直接拿去用的
代码片段和文件信息
%KNN classifiers
%training is training set testing is test set
%D is the distance D=1 is mandistance; D=2 is 欧氏距离 D=3是 infinite norm
% K is the number of selected neighbors
function label=KNN(trainingtestingDK)
[row column]=size(training);
[row1 column1]=size(testing);
%计算测试集与训练集的距离
distance=[];
if D==1
for i=1:row1
for j=1:row
temp=[training(j[1:(column-1)]);testing(i:)];
d=mandist(temp);
distance(ij)=d(12);
end
end
end
if D==2
for i=1:row1
for j=1:row
temp=[training(j[1:(column-1)]);testing(i:)]‘;
d=dist(temp);
distanc
- 上一篇:免疫遗传算法
- 下一篇:谐波恢复中的SVD_TLS算法
评论
共有 条评论