Guest User

Untitled

a guest
Feb 24th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. library(MASS)
  2. data(Pima.tr)
  3. data(Pima.te)
  4. ?Pima.tr
  5.  
  6. #glm(type~age,data=Pima.tr)
  7. #glm(type~age+ped+bp,data=Pima.tr)
  8.  
  9. glm1<-glm(type~npreg+glu+skin+bmi+age+ped+bp,data=Pima.tr, family="binomial")
  10. pp1<-predict(glm1, data = Pima.tr, type = "response")
  11.  
  12. pred_tr=NULL
  13. pred_tr[pp1<0.5]<-1
  14. pred_tr[pp1>=0.5]<-2
  15.  
  16. confusion<-cbind(pred_tr,Pima.tr$type)
  17.  
  18. sum(confusion[,1]==2&confusion[,2]==2)
  19. sum(confusion[,1]==1&confusion[,2]==1)
  20. sum(confusion[,1]==1&confusion[,2]==2)
  21. sum(confusion[,1]==2&confusion[,2]==1)
  22.  
  23. glm2<-glm(glm1,data=Pima.te,family="binomial")
  24. pp2 <- predict(glm2, data = Pima.te, type = "response")
  25.  
  26. pred_test=NULL
  27. pred_test[pp2<0.5]<-1
  28. pred_test[pp2>=0.5]<-2
  29.  
  30. confusion2<-cbind(pred_test,Pima.te$type)
  31.  
  32. sum(confusion2[,1]==2&confusion2[,2]==2)
  33. sum(confusion2[,1]==1&confusion2[,2]==1)
  34. sum(confusion2[,1]==1&confusion2[,2]==2)
  35. sum(confusion2[,1]==2&confusion2[,2]==1)
Add Comment
Please, Sign In to add comment