22 lines
789 B
Mathematica
22 lines
789 B
Mathematica
|
% implements KNN_Error, returns nothing but prints out a table of test
|
||
|
% errors for k-nearest neighbors using different values of k.
|
||
|
function [] = KNN_Error(neigenvectors, ks, training_data, test_data, training_labels, test_labels)
|
||
|
|
||
|
% TODO: perform PCA
|
||
|
|
||
|
% TODO: project data using the number of eigenvectors defined by neigenvectors
|
||
|
|
||
|
% TODO: compute test error for kNN with differents k's. Fill in
|
||
|
% test_errors with the results for each k in ks.
|
||
|
test_errors = zeros(1,length(ks));
|
||
|
|
||
|
% print error table
|
||
|
fprintf("-----------------------------\n");
|
||
|
fprintf("| k | test error\n")
|
||
|
fprintf("-----------------------------\n");
|
||
|
for i = 1:length(ks)
|
||
|
fprintf("| %d | %.8f \n", ks(i), test_errors(i));
|
||
|
end
|
||
|
fprintf("-----------------------------\n");
|
||
|
|
||
|
end % Function end
|