Out[2]:
|
PassengerId |
Survived |
Pclass |
Name |
Sex |
Age |
SibSp |
Parch |
Ticket |
Fare |
Cabin |
Embarked |
0 |
1 |
0 |
3 |
Braund, Mr. Owen Harris |
male |
22 |
1 |
0 |
A/5 21171 |
7.2500 |
NaN |
S |
1 |
2 |
1 |
1 |
Cumings, Mrs. John Bradley (Florence Briggs Th... |
female |
38 |
1 |
0 |
PC 17599 |
71.2833 |
C85 |
C |
2 |
3 |
1 |
3 |
Heikkinen, Miss. Laina |
female |
26 |
0 |
0 |
STON/O2. 3101282 |
7.9250 |
NaN |
S |
3 |
4 |
1 |
1 |
Futrelle, Mrs. Jacques Heath (Lily May Peel) |
female |
35 |
1 |
0 |
113803 |
53.1000 |
C123 |
S |
4 |
5 |
0 |
3 |
Allen, Mr. William Henry |
male |
35 |
0 |
0 |
373450 |
8.0500 |
NaN |
S |
https://www.kaggle.com/c/titanic-gettingStarted/data?train.csv
VARIABLE DESCRIPTIONS:
survival Survival
(0 = No; 1 = Yes)
pclass Passenger Class
(1 = 1st; 2 = 2nd; 3 = 3rd)
name Name
sex Sex
age Age
sibsp Number of Siblings/Spouses Aboard
parch Number of Parents/Children Aboard
ticket Ticket Number
fare Passenger Fare
cabin Cabin
embarked Port of Embarkation
(C = Cherbourg; Q = Queenstown; S = Southampton)
SPECIAL NOTES:
Pclass is a proxy for socio-economic status (SES)
1st ~ Upper; 2nd ~ Middle; 3rd ~ Lower
Age is in Years; Fractional if Age less than One (1)
If the Age is Estimated, it is in the form xx.5
With respect to the family relation variables (i.e. sibsp and parch)
some relations were ignored. The following are the definitions used
for sibsp and parch.
Sibling: Brother, Sister, Stepbrother, or Stepsister of Passenger Aboard Titanic
Spouse: Husband or Wife of Passenger Aboard Titanic (Mistresses and Fiances Ignored)
Parent: Mother or Father of Passenger Aboard Titanic
Child: Son, Daughter, Stepson, or Stepdaughter of Passenger Aboard Titanic
Other family relatives excluded from this study include cousins,
nephews/nieces, aunts/uncles, and in-laws. Some children travelled
only with a nanny, therefore parch=0 for them. As well, some
travelled with very close friends or neighbors in a village, however,
the definitions do not support such relations.
Out[3]:
PassengerId int64
Survived int64
Pclass int64
Name object
Sex object
Age float64
SibSp int64
Parch int64
Ticket object
Fare float64
Cabin object
Embarked object
dtype: object
Out[4]:
<matplotlib.axes.AxesSubplot at 0x3646890>
Out[6]:
<matplotlib.axes.AxesSubplot at 0x3787550>
# TODO
# visualise survival versus sex - maybe a stacked bar chart? at least do a simple percentage calculation and print the result
# visualise age vs fare as a scatter chart and colour the markers to show survival - do we see a pattern?
# maybe modify the scatter plot to show Pclass using a symbol (e.g. square, triangle, circle) as an addition, so we show 4 dimensions (age, fare, Pclass, survival) on a 2D chart
0 True
1 False
2 False
3 False
4 True
Name: Sex, dtype: bool
0 True
1 False
2 False
3 False
4 True
Name: Sex, dtype: bool
Out[10]:
PassengerId int64
Survived int64
Pclass int64
Name object
Sex object
Age float64
SibSp int64
Parch int64
Ticket object
Fare float64
Cabin object
Embarked object
is_male bool
dtype: object
Out[11]:
|
PassengerId |
Survived |
Pclass |
Name |
Sex |
Age |
SibSp |
Parch |
Ticket |
Fare |
Cabin |
Embarked |
is_male |
0 |
1 |
0 |
3 |
Braund, Mr. Owen Harris |
male |
22 |
1 |
0 |
A/5 21171 |
7.2500 |
NaN |
S |
True |
1 |
2 |
1 |
1 |
Cumings, Mrs. John Bradley (Florence Briggs Th... |
female |
38 |
1 |
0 |
PC 17599 |
71.2833 |
C85 |
C |
False |
2 |
3 |
1 |
3 |
Heikkinen, Miss. Laina |
female |
26 |
0 |
0 |
STON/O2. 3101282 |
7.9250 |
NaN |
S |
False |
3 |
4 |
1 |
1 |
Futrelle, Mrs. Jacques Heath (Lily May Peel) |
female |
35 |
1 |
0 |
113803 |
53.1000 |
C123 |
S |
False |
4 |
5 |
0 |
3 |
Allen, Mr. William Henry |
male |
35 |
0 |
0 |
373450 |
8.0500 |
NaN |
S |
True |
577 (64.76%) males of 891.0 people
342 people survived
109 males survived
Out[13]:
|
Survived |
is_male |
0 |
0 |
True |
1 |
1 |
False |
2 |
1 |
False |
3 |
1 |
False |
4 |
0 |
True |
Out[14]:
|
Survived |
Pclass |
0 |
0 |
3 |
1 |
1 |
1 |
2 |
1 |
3 |
3 |
1 |
1 |
4 |
0 |
3 |
0 True
1 False
2 False
3 False
4 True
Name: is_male, dtype: bool
Out[17]:
DecisionTreeClassifier(compute_importances=None, criterion='gini',
max_depth=None, max_features=None, min_density=None,
min_samples_leaf=1, min_samples_split=2, random_state=None,
splitter='best')
Score: 0.786756453423
Feature importances [ 1.]
Out[19]:
|
PassengerId |
Pclass |
Name |
Sex |
Age |
SibSp |
Parch |
Ticket |
Fare |
Cabin |
Embarked |
is_male |
0 |
892 |
3 |
Kelly, Mr. James |
male |
34.5 |
0 |
0 |
330911 |
7.8292 |
NaN |
Q |
True |
1 |
893 |
3 |
Wilkes, Mrs. James (Ellen Needs) |
female |
47.0 |
1 |
0 |
363272 |
7.0000 |
NaN |
S |
False |
2 |
894 |
2 |
Myles, Mr. Thomas Francis |
male |
62.0 |
0 |
0 |
240276 |
9.6875 |
NaN |
Q |
True |
3 |
895 |
3 |
Wirz, Mr. Albert |
male |
27.0 |
0 |
0 |
315154 |
8.6625 |
NaN |
S |
True |
4 |
896 |
3 |
Hirvonen, Mrs. Alexander (Helga E Lindqvist) |
female |
22.0 |
1 |
1 |
3101298 |
12.2875 |
NaN |
S |
False |
Total predicted survivor rate: 152
In the diagram above the field `is_male` is boolean but the Decision Tree represents it as a number, so the <= 0.5 test is saying "if 0 then go left, if 1 then go right". 0 is False so the left branch is for females, the right branch is for males. The two leaf nodes (on the second row) use the same output `value`. Column 0 is for Survived==0 (i.e. the number who died), column 1 is for Survived==1 (i.e. those who lived).
You can see that 109 males survived. Confirm this with the result a few cells above where we calculated the number of men who survived.
Question - how many females died?
Next you should read more on the Kaggle website about "Getting Started" for this competition, it gives some hints about where to go next.