In [ ]:
The sinking of the RMS Titanic is one of the most infamous shipwrecks in history. On April 15, 1912, during her maiden voyage, the Titanic sank after colliding with an iceberg, killing 1502 out of 2224 passengers and crew. This sensational tragedy shocked the international community and led to better safety regulations for ships.
One of the reasons that the shipwreck led to such loss of life was that there were not enough lifeboats for the passengers and crew. Although there was some element of luck involved in surviving the sinking, some groups of people were more likely to survive than others, such as women, children, and the upper-class.
In this challenge, we ask you to complete the analysis of what sorts of people were likely to survive. In particular, we ask you to apply the tools of machine learning to predict which passengers survived the tragedy.
In [ ]:
In [ ]:
In [72]:
# #Load the data into a dataframe
titanic_train = read.csv("train.csv", header=T, na.strings=c("","NA"))
In [73]:
# #Structure of the data
str(titanic_train)
In [74]:
head(titanic_train)
Out[74]:
In [75]:
summary(titanic_train)
Out[75]:
In [ ]:
In [ ]:
In [ ]:
In [76]:
# #The dependent variable is "Survived" - 0 or 1 AND all the other variables are the independent variables
In [77]:
titanic_train_cleaned = titanic_train[, !(colnames(titanic_train) %in% c("Name","Ticket", "Cabin"))]
In [78]:
head(titanic_train_cleaned)
Out[78]:
In [ ]:
In [ ]:
In [79]:
# #Comparing the number of Men and Women who survived
table(titanic_train_cleaned$Survived, titanic_train_cleaned$Sex)
Out[79]:
In [80]:
# #Percentage of Women who survived
233*100/(233+81)
Out[80]:
In [81]:
# #Percentage of Men who survived
109*100/(109+468)
Out[81]:
In [ ]:
In [ ]:
In [ ]:
In [82]:
# titanic_train_cleaned$Sex = as.factor(titanic_train_cleaned$Sex)
# titanic_train_cleaned$Embarked = as.factor(titanic_train_cleaned$Embarked)
In [83]:
#titanic_train_cleaned$Age = as.integer(titanic_train_cleaned$Age)
In [84]:
#titanic_train_cleaned$Fare = as.integer(titanic_train_cleaned$Fare)
In [ ]:
In [ ]:
In [85]:
model_1 = glm(Survived ~ ., data = titanic_train_cleaned, family = "binomial")
In [86]:
summary(model_1)
Out[86]:
In [ ]: