Skip to content

Instantly share code, notes, and snippets.

@yuu-ito
Created April 25, 2014 10:02
Show Gist options
  • Save yuu-ito/11284310 to your computer and use it in GitHub Desktop.
Save yuu-ito/11284310 to your computer and use it in GitHub Desktop.
# kaggle titanic
# https://www.kaggle.com/c/titanic-gettingStarted/data
t <- read.csv("../../Downloads/train.csv")
names(t)<-tolower(names(t))
idx<- sample(nrow(t),(nrow(t)*0.7))
t.tr <- t[ idx,]
t.te <- t[-idx,]
table(t.tr$survived)/nrow(t.tr)
table(t.te$survived)/nrow(t.te)
head(t.tr)
g <- glm(data=t.tr, survived~pclass+sex+age+sibsp+parch)
p <- predict(g,t.te)
t.pred <- data.frame(t.te, p)
head(t.pred)
t.pred$p_factor <- cut(t.pred$p,breaks=c(-1,0.55,2))
table(t.pred$p_factor,t.pred$survived)
sum(diag(table(t.pred$p_factor,t.pred$survived)))/nrow(t.pred)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment