Home > chronux_1_1 > locfit > Book > fig8_2.m

fig8_2

PURPOSE ^

Local Regression and Likelihood, Figure 8.2.

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 Local Regression and Likelihood, Figure 8.2.

 Discrimination/Classification, simple example using
 density estimation.

 First, compute density estimates fit0, fit1 ('family','rate'
 - output is in events per unit area) for each class in the
 training sample. The ratio fit1/(fit1+fit0) estimates the
 posterior probability that an observation comes from population 1.

 plotting the classification boundary is slightly tricky - it depends
 on both fits, so lfplot() can't be used. Instead, both fits must be
 evaluated on the same grid of values, which is then used to make a
 contour plot.

 Author: Catherine Loader

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Local Regression and Likelihood, Figure 8.2.
0002 %
0003 % Discrimination/Classification, simple example using
0004 % density estimation.
0005 %
0006 % First, compute density estimates fit0, fit1 ('family','rate'
0007 % - output is in events per unit area) for each class in the
0008 % training sample. The ratio fit1/(fit1+fit0) estimates the
0009 % posterior probability that an observation comes from population 1.
0010 %
0011 % plotting the classification boundary is slightly tricky - it depends
0012 % on both fits, so lfplot() can't be used. Instead, both fits must be
0013 % evaluated on the same grid of values, which is then used to make a
0014 % contour plot.
0015 %
0016 % Author: Catherine Loader
0017 
0018 load cltrain;
0019 u0 = find(y==0);
0020 u1 = find(y==1);
0021 fit0 = locfit([x1(u0) x2(u0)],y(u0),'family','rate','scale',0);
0022 fit1 = locfit([x1(u1) x2(u1)],y(u1),'family','rate','scale',0);
0023 
0024 v0 = -3+6*(0:50)'/50;
0025 v1 = -2.2+4.2*(0:49)'/49;
0026 % predict returns log(rate)
0027 z = predict(fit0,{v0 v1})-predict(fit1,{v0 v1});
0028 z = reshape(z,51,50);
0029 contour(v0,v1,z',[0 0]);
0030 hold on;
0031 plot(x1(u0),x2(u0),'.');
0032 plot(x1(u1),x2(u1),'.','color','red');
0033 hold off;
0034 
0035 p0 = predict(fit0,[x1 x2]);
0036 p1 = predict(fit1,[x1 x2]);
0037 py = (p1 > p0);
0038 disp('Classification table for training data');
0039 tabulate(10*y+py);
0040 
0041 load cltest;
0042 p0 = predict(fit0,[x1 x2]);
0043 p1 = predict(fit1,[x1 x2]);
0044 py = (p1 > p0);
0045 disp('Classification table for test data');
0046 tabulate(10*y+py);
0047

Generated on Sun 13-Aug-2006 11:49:44 by m2html © 2003