csci5521/assignments/hwk02/KNN_Error.m

22 lines
789 B
Mathematica
Raw Normal View History

2023-10-12 23:51:06 +00:00
% 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