close all % Close all figure windows clear all % Clear all variables in memory %loadiris; loadaba; % ====== Data normalization to have zero mean and unity variance r.v. new_feature = normal(feature); data = [new_feature output]; misclassify = zeros(feature_n, 1); all_in_n = size(data, 2)-1; in_n = 3; model_n = prod(1:all_in_n)/(prod(1:in_n)*prod(1:(all_in_n-in_n))); index = zeros(model_n, in_n); misclassify = zeros(model_n, 1); K = 1; % ====== Construct KNNR with different input variables fprintf('\nConstruct %d KNNR models, each with %d inputs selected from %d candidates...\n\n',... model_n, in_n, all_in_n); % ====== You need to replace the following lines to generate % "index" and "misclassify" via exhaustive search index = [ 1 6 7; % Inputs 1, 6, and 7 are selected 2 5 6; % Inputs 2, 5, and 6 are selected 1 3 4; % Inputs 1, 3, and 4 are selected 3 4 6; % Inputs 3, 4, and 6 are selected 2 4 5; % Inputs 2, 4, and 5 are selected 4 6 7; % Inputs 4, 6, and 7 are selected 1 4 5; 1 3 8; 4 5 8; 2 6 8; 2 4 6; 1 6 8; 1 5 6; 1 4 7; 2 6 7; 1 3 6; 3 6 8; 1 5 7; 1 3 7; 1 2 6; 5 6 8; 4 5 6; 3 5 8; 2 7 8; 2 5 8; 1 5 8; 1 4 8; 3 4 5; 2 3 6; 2 3 4; 1 7 8; 1 3 5; 2 4 7; 2 3 5; 1 2 5; 1 2 3; 6 7 8; 5 6 7; 4 5 7; 3 4 7; 2 3 7; 1 2 7; 1 2 4; 4 7 8; 4 6 8; 3 5 6; 3 4 8; 1 4 6; 1 2 8; 5 7 8; 3 7 8; 2 5 7; 3 6 7; 3 5 7; 2 3 8; 2 4 8]; misclassify = floor(50*rand(model_n,1)); % ====== Don't change anything below this line! % ====== Reordering according to misclassification numbers [a b] = sort(misclassify); b = flipud(b); % List according to decreasing trn error misclassify = misclassify(b); index = index(b, :); % ====== Display the results figTitle = 'Exhaustive Input Selection'; figure('Name', figTitle, 'NumberTitle', 'off'); x = (1:model_n)'; error_rate = misclassify/size(data,1)*100; [a, b] = min(error_rate); fprintf('Minimal error rate = %.1f%%.\n', a); fprintf('Selected inputs: '); for p = 1:in_n, fprintf(' %s', deblank(input_name(index(size(index,1),p), :))); end fprintf('\n'); subplot(211); plot(x, error_rate, '-', x, error_rate, 'co'); tmp = x(:, ones(1, 3))'; X = tmp(:); tmp = [zeros(model_n, 1) error_rate nan*ones(model_n, 1)]'; Y = tmp(:); hold on; plot(X, Y, 'g'); hold off; axis([-inf inf 0 100]); axis([1 model_n -inf inf]); set(gca, 'xticklabels', []); ylabel('LOU Error Rates (%)'); grid on h = findobj(gcf, 'type', 'line'); set(h, 'linewidth', 2) % ====== Add text of input variables for k = 1:model_n, text(x(k), 0, ... [deblank(input_name(index(k,1), :)) ' ' ... deblank(input_name(index(k,2), :)) ' ' ... deblank(input_name(index(k,3), :)) ' ']); end h = findobj(gcf, 'type', 'text'); set(h, 'rot', 90, 'fontsize', 9, 'hori', 'right'); title(['Exhaustive Search for ', int2str(in_n), ' Inputs']);