close all % Close all figure windows clear all % Clear all variables in memory fprintf('Loading "abalone.dat"...\n'); load abalone.dat % Load the data set feature_n = size(abalone, 2)-1; % no. of features instance_n = size(abalone, 1); % no. of instances feature = abalone(:, 1:feature_n); % feature matrix output = abalone(:, feature_n+1); % output matrix [a, b] = countele(output); class_n = length(a); % No. of classes fprintf('%g features\n', feature_n); fprintf('%g instances\n', instance_n); fprintf('%g classes\n', class_n); % Plot age distribution %bar(a, b); %xlabel('Age'); %ylabel('Counts'); %title('Age Distribution for the Abalone Data Set'); fprintf('Class 1: %g instances are younger than 10 years\n',... length(find(output<10))); fprintf('Class 2: %g instances are equal to or older than 10 years\n',... length(find(output>=10))); % Modify the data set such that instances younger than 10 years fall % into class 1; all the others into class 2 index1 = find(output<10); output(index1) = 1*ones(size(index1)); index2 = find(output>=10); output(index2) = 2*ones(size(index2)); % Data normalization to have zero mean and unity variance r.v. new_feature = normal(feature); data = [new_feature output]; misclassify = zeros(10, 1); tic for k = 1:10, instance_n = size(data, 1); % [misclassify(k), index] = louerror(data, k, 1); [misclassify(k), index] = louerror(data, k); fprintf('Recognition rate = %g\n', 1-misclassify(k)/instance_n); end toc x = 1:10; y = (1-misclassify/instance_n)*100; plot(x, y, '-', x, y, 'co'); xlabel('"K" in KNNR'); ylabel('LOU Recognition Rates (%)'); grid on h = findobj(gcf, 'type', 'line'); set(h, 'linewidth', 2)