Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to add the titanic predictive analysis algorithm #4

Open
ghost opened this issue Jun 14, 2018 · 0 comments
Open

I want to add the titanic predictive analysis algorithm #4

ghost opened this issue Jun 14, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Jun 14, 2018

Hi i'm a South-Korean university student studying data science. I'm interested in Titanic data analysis. Your project is the best Titanic prediction algorithm I have ever seen. It was a great help to study. So I would like to send you the R code I analyzed(association rule, Regression analysis )

Titanic dataset.zip

`data<- read.csv("file location", header=T, na.strings=c("."))
data$survived <- factor(data$survived,levels=c(1,0),labels = c("y","n"))
data$pclass <- factor(data$pclass,levels=c(1,2,3),labels = c("1 grade","2 grade","3 grade"))
data$sibsp <- factor(data$sibsp,levels=c(0,1,2,3,4,5,8),labels = c("0","1","2","3","4","5","8"))
data$parch <- factor(data$parch,levels=c(0,1,2,3,4,5,6,9),labels = c("0","1","2","3","4","5","6","9"))
data <- data.frame(data$survived,data$pclass,data$sex,data$sibsp,data$parch,data$embarked,
data$age1,data$fare1)
#association rule

summary(data)
install.packages("arules")
library(arules)
rules.all <- apriori(data)

inspect(rules.all)

rules <- apriori(data,
control = list(verbose=F),
parameter = list(minlen = 2, supp = 0.005, conf=0.8),
appearance = list(rhs=c("data.survived=n",
"data.survived=y"),
default="lhs"))

quality(rules) <- round(quality(rules),digits=3)

rules.sorted <- sort(rules, by = "lift")

inspect(rules.sorted[1:2])

subset.matrix <- is.subset(rules.sorted, rules.sorted)
subset.matrix

redundant <- colSums(subset.matrix) > 0
redundant

rules.pruned <- rules.sorted[!redundant]
inspect(rules.pruned)

inspect(rules.pruned[1])

rules_1 <- apriori(data,
control = list(verbose=F),
parameter = list(minlen = 2, supp = 0.002, conf=0.2),
appearance = list(rhs=c("data.survived=n"),
lhs=c("data.pclass=1 grade",
"data.pclass=2 grade",
"data.pclass=3 grade",
"data.age1=kid","data.age1=adult"),
default="none"))
rules_1_sorted <- sort(rules_1,by="confidence")
inspect(rules_1_sorted)

//visual

install.packages("arulesViz")
library(arulesViz)
plot(rules.all)
plot(rules.all, method = "grouped")

#Regression analysis

data2 <- read.csv("C:/Users/dprnj/OneDrive/문서/KYK/Rworks/StatwithR/ch1/Data/titanic_full_2.csv", header=T, na.strings=c("."))
str(data2)
data2<-na.omit(data2)
plot(data2$sex,data2$survived)
cor(data2)
result1<-lm(data2$survived~data2$sex+data2$age+data2$fare,data=data2)
summary(result1)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants