function fig3(x, y, xt, yt)
%fig3(x,y)

%	Ling Li, Caltech
%	11/17/2000

if nargin < 4
	load train3.dat
	load test3.dat
	x = train3(:, 1:2)';
	y = train3(:, 3)';
	xt = test3(:, 1:2)';
	yt = test3(:, 3)';
end

ks = 1:2:15;

K = length(ks);
N = size(x, 2);
NT = size(xt, 2);

errs = zeros(1,K);

for i = 1:K
	ye = kneighbor(xt, x, y, ks(i));
	errs(i) = sum(yt ~= ye)/NT;
end

ests = zeros(1,K);
for i = 1:K
	ests(i) = kneighest(x, y, ks(i));
end

figure; hold on;
plot(ks, errs, 'bo-');
errorbar(ks, ests, sqrt(ests.*(1-ests)/N), 'r-');
%errorbar(ks, ests/2, sqrt(ests.*(1-ests)/N), 'g-');
legend('oos error', 'est. error');
xlabel('K');
ylabel('percentage of mis-classified points');