fig8_1.m 639 B

12345678910111213141516171819202122232425262728
  1. % Local Regression and Likelihood, Figure 8.1.
  2. %
  3. % Discrimination/Classification, simple example using
  4. % logistic regression.
  5. %
  6. % Author: Catherine Loader
  7. %
  8. % NEED: level=0.5 for contour plot.
  9. load cltrain;
  10. fit = locfit([x1 x2],y,'family','binomial','scale',0);
  11. figure('Name','fig8_1: logistic regression');
  12. lfplot(fit,'contour');
  13. hold on;
  14. u = find(y==0);
  15. plot(x1(u),x2(u),'.');
  16. u = find(y==1);
  17. plot(x1(u),x2(u),'.','color','red');
  18. hold off;
  19. py = fitted(fit)>0.5;
  20. disp('Classification table for training data');
  21. tabulate(10*y+py);
  22. load cltest;
  23. py = predict(fit,[x1 x2])>0;
  24. disp('Classification table for test data');
  25. tabulate(10*y+py);