|
Monday, October 13, 2008 |
Activity 19: Linear Discriminant Analysis |
Moving on to our discussion about pattern recognition we study Linear Discriminant Analysis or LDA. Here we create a discriminant function from predictor variables. Here I tried classifying 5 centavo and 25 centavo coins.
This time since both are (should be) circular, I remove the parameter of Height over Width leaving three parameters for classifications: Area, R (NCC) and G (NCC). The code I used is shown below: x = [1239 0.602028 0.283912; 1224 0.629195 0.280192; 1206 0.611142 0.289349; 2080 0.520683 0.374020; 2064 0.529127 0.382716; 1977 0.582884 0.345742]; xt = [1264 0.633988 0.271862; 1179 0.618832 0.278147; 1191 0.615691 0.280110; 2000 0.499452 0.372944; 1956 0.499452 0.379350; 1906 0.522208 0.392979];//Test class y = [1; 1; 1; 2; 2; 2;]; x1 = [1239 0.602028 0.283912; 1224 0.629195 0.280192; 1206 0.611142 0.289349]; x2 = [2080 0.520683 0.374020; 2064 0.529127 0.382716; 1977 0.582884 0.345742]; n1 = size(x1, 1); n2 = size(x2, 1); m1 = mean(x1, 'r'); m2 = mean(x2, 'r'); m = mean(x, 'r'); x1o = x1 - mtlb_repmat(m, [n1, 1]); x2o = x2 - mtlb_repmat(m, [n2, 1]); c1 = (x1o'*x1o)/n1; c2 = (x2o'*x2o)/n2; C = (n1/(n1+n2))*c1 + (n2/(n1+n2))*c2; p = [n1/(n1+n2); n2/(n1+n2)]; CI = inv(C); for i = 1:size(xt, 1) xk = xt(i, :); f1(i) = m1*CI*xk' - 0.5*m1*CI*m1' + log(p(1)); f2(i) = m2*CI*xk' - 0.5*m2*CI*m2' + log(p(2)); end class = f1 - f2; class(class >= 0) = 1; class(class < 0) = 2;
Again, 100% classification was shown.
Acknowledgments Thanks to Ed for the code! I totally rocked this activity! I give myself 10/10 neutrinos!
|
posted by poy @ 12:41 AM |
|
|
|
|
|