Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N1 = 10; N2 = 15; % Class sizes
- set1=[0.333; 0.509; 0.607; 1.172; 0.275; 0.762; 0.850; 0.920; 0.556; -0.046];
- set2=[ 0.295; -0.203; -0.097; 0.633; 0.147; 0.356; 0.235; -0.054; -0.024; 0.377; -0.180; 0.512; 0.428; -0.129; 0.094];
- %define your domain of interest
- dx = 0.001;
- x = [-1.0:dx:2.0];
- %step through each point and decide which class it is part of
- x_class = NaN*ones(size(x));
- for I=1:length(x)
- %apply your KNN decision algorithm here
- %it outputs a 1 for class 1, or it outputs a 2 for class 2
- x_class(I) = my_KNN_algorithm(set1,set2,rules,x(I));
- end
- %plot results
- plot(x,x_class);
- hold on;
- plot(set1,ones(size(set1)),'ro');
- plot(set2,2*ones(size(set2)),'gs');
- xlabel('Value');
- ylabel('Class');
- legend('Test Point','Given Set 1','Given Set 2')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement