layout: post
title: Titanic Survivors
---

Predicting the Survival of Titanic Passengers

In April 1912, the Titanic passenger liner sank in the North Atlantic Ocean after
colliding with an iceberg. Of the almost 2,500 passengers, the death toll has been
estimated between 1,490 and 1,635. Using a dataset that includes information regarding
891 of the passengers, I attempted to determine which factors were most important
when trying to predict whether a passenger survived or not.

The dataset, at the passenger level, included ID, Name, whether the passenger
survived, sex, age, ticket id, and the port that the passenger boarded the Titanic.
There are also fields for the number of siblings or spouses on board, the number
of parents or children on board, and the class the patient was staying in. As the
dataset only includes a third of all passengers, we must trust that these passengers
were selected randomly and there are no biases in the sample.

Unfortunately, the age field is sparsely populated. It would have been interesting
to see how passenger age effected survival rate, but the data is not populated
sufficiently. At the very lest, we are able to tell that age was distributed the same
way between gender:

![titanic_age](/images/titanic_age_distribution.png)

Two fields immediately appear to be important: gender and class:

![titanic_summary](/images/Titanic_summary.png)

While there are over 200 more total male passengers in our sample set, the number
of female passengers who survived significantly out weight the number of male passengers
who survived. It also also clear that class was very important. A passenger was
much less likely to survive if they had only purchased a third class ticket.

I used logistic regression, with survival as my dependent variable to predict chances of
survival. My features included a dummy variable for gender, dummies for first and
second class, the number of siblings/spouses, and the number of parents/children.
As expected, the male dummy variable had a negative coefficient - men were much
less likely to survive than women. Similarly, as expected, passengers in first or
second class were much more likely to survive than passengers in third class. Both
variables representing the number of family members on board had much smaller, but
negative effects on survival rate.

The logistic model does a fairly good job of predicting survivors. A five fold
cross val score was .79, and a ROC curve shows a strong True Positive rate.

![titanic_roc](/images/titanic_roc.png)

Using k Nearest Neighbors and GridSearchCV notably improved our model. The new ROC
curve shows a stronger True Positive rate, and a Confusion Matrix shows an increase
in both True Positives and True Negatives.

![titanic_roc2](/images/titanic_roc2.png)
