fig8_3.m 935 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. % Local Regression and Likelihood, Figure 8.3.
  2. %
  3. % Discrimination/Classification, iris data for different
  4. % smooting paramters.
  5. %
  6. % Note that the iris.mat file contains the full iris dataset;
  7. % only Versicolor and Virginica are used in this example.
  8. %
  9. % The `Species' variable contains species names. `Specn' has
  10. % them numerically, Setosa=1, Versicolor=2, Virginica=3.
  11. %
  12. % Author: Catherine Loader
  13. %
  14. % Need: get contour plot correct.
  15. % Need: distinguish colors in plot.
  16. load iris;
  17. a = (2:9)/10;
  18. z = zeros(size(a));
  19. u = find(Specn >= 2);
  20. pw = PetalWid(u);
  21. pl = PetalLen(u);
  22. y = (Specn(u)==3);
  23. for i = 1:length(a)
  24. fit = locfit([pw pl],y,'deg',1,'alpha',a(i),'ev','cros','scale',0,'family','binomial');
  25. fv = fitted(fit);
  26. tb = tabulate(10*y+(fv>=0.5))
  27. z(i) = sum(y == (fv<=0.5));
  28. end;
  29. [a; z]
  30. fit = locfit([pw pl],y,'deg',1,'scale',0,'family','binomial');
  31. figure('Name','fig8_3: iris classification');
  32. lfplot(fit,'contour');