?? knn_lighttest.asv
字號:
function knn_lightTest
proto = [
0.6213 0.7373
0.5226 0.8939
0.9797 0.6614
0.9568 0.0118
0.8801 0.1991
0.8757 0.0648
0.1730 0.2987
0.2714 0.2844
0.2523 0.4692
];
protoClass = [
1
1
1
2
2
2
3
3
3
];
data = [
0.9883 0.4329
0.5828 0.2259
0.4235 0.5798
0.5155 0.7604
0.3340 0.5298
];
% main
dataClass = knn_light(data, proto, protoClass,1);
% plot proto
classLabel = unique(protoClass);
nClass = length(classLabel);
plotLabel = {'r*', 'g*', 'b*'};
for i=1:nClass
A = proto(protoClass == classLabel(i), :);
plot(A(:, 1), A(:, 2), plotLabel{i});
hold on;
end
% plot data
plotLabel = {'ro', 'go', 'bo'};
for i=1:3
A = data(dataClass == classLabel(i), :);
plot(A(:, 1), A(:, 2), plotLabel{i});
hold on;
end
legend('1: proto','2: proto', '3: proto', '1: data', '2: data', '3: data');
title('K nearest neighbor');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -