Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. library(pROC)
  2. d<- data.frame(Titanic)
  3. d$Survived <- ifelse(d$Survived == "No", 0,1)
  4. m<- glm(Survived ~ Class+Sex+Age+Freq, data=d, family = binomial(link = "logit"))
  5. fitted.results <- predict(m,newdata=subset(d,select=c(1,2,3,5)),type='response')
  6. auc(d$Survived, fitted.results)
  7.  
  8.  
  9. ### unbalancing the data by converting y to 1 where freq is even( just a random condition)
  10.  
  11. d$Survived_unbalanced <-ifelse(d$Freq %% 2 == 0,1,d$Survived)
  12. m_ub<- glm(Survived_unbalanced ~ Class+Sex+Age+Freq, data=d, family = binomial(link = "logit"))
  13. fitted.results_ub <- predict(m_ub,newdata=subset(d,select=c(1,2,3,5)),type='response')
  14. auc(d$Survived_unbalanced, fitted.results_ub)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement