Skip to content

Dataset Guide — Titanic Survival Prediction

Before writing a single line of modelling code, you need to know your data. This file is your reference for the Titanic dataset: what every column means, which ones are missing, which ones are redundant, and why they exist in the first place. Read this before starting the EDA.

Loading the Dataset

import seaborn as sns
import pandas as pd

df = sns.load_dataset('titanic')

print(df.shape)
# Output: (891, 15)

print(df.dtypes)
# Output:
# survived         int64
# pclass           int64
# sex             object
# age            float64
# sibsp            int64
# parch            int64
# fare           float64
# embarked        object
# class         category
# who             object
# adult_male        bool
# deck          category
# embark_town     object
# alive           object
# alone             bool

The dataset has 891 rows (passengers) and 15 columns. It is the standard Kaggle training set — the full Titanic had 2,224 people aboard, but this subset is the one used in the world's most-run Kaggle competition.

Column Reference

Column Type Description Missing Values
survived int (0/1) Target variable. 1 = survived, 0 = died. 0
pclass int (1/2/3) Passenger class. 1 = first, 2 = second, 3 = third. A proxy for socioeconomic status. 0
sex category Passenger sex: male or female. One of the strongest predictors. 0
age float Passenger age in years. Infants have fractional ages (e.g., 0.42). 177 (~19.9%)
sibsp int Number of siblings or spouses aboard. 0
parch int Number of parents or children aboard. 0
fare float Ticket price in pre-1912 British pounds. Correlated with class. 0
embarked category Port of embarkation: C = Cherbourg, Q = Queenstown, S = Southampton. 2
class category Text version of pclass: First, Second, Third. 0
who category Simplified grouping: man, woman, or child. Derived from sex and age. 0
adult_male bool True if the passenger is an adult male. 0
deck category Cabin deck letter (A through G, drawn from ticket number). 688 (~77.2%)
embark_town category Full name version of embarked: Cherbourg, Queenstown, Southampton. 2
alive category Text version of survived: yes or no. 0
alone bool True if the passenger was travelling alone (sibsp + parch == 0). 0

Redundant Columns

Several columns contain the same information in a different format. Keeping both versions wastes memory, confuses the model, and inflates feature importance scores. Drop the redundant one in each pair.

Keep Drop Reason
pclass class class is the categorical string version of the integer pclass.
embarked embark_town Same information. embarked is already coded as a short category.
survived alive alive is yes/no — a string encoding of the target. Leaving it in causes target leakage.
sex + age who who is derived from these two columns. It adds no new information.
sibsp + parch alone alone is a boolean derived from sibsp + parch == 0. You will recreate this as is_alone.

Warning

Drop alive immediately after loading. It is a direct string encoding of the target variable survived. If you forget to drop it and it ends up in your feature matrix, your model will achieve ~100% accuracy and learn nothing. This is target leakage.

Missing Values Summary

import seaborn as sns
import pandas as pd

df = sns.load_dataset('titanic')

missing = df.isnull().sum()
missing_pct = (df.isnull().mean() * 100).round(1)

missing_summary = pd.DataFrame({
    'Missing Count': missing,
    'Missing %': missing_pct
}).loc[missing > 0]

print(missing_summary.sort_values('Missing %', ascending=False))
# Output:
#              Missing Count  Missing %
# deck                   688       77.2
# age                    177       19.9
# embark_town              2        0.2
# embarked                 2        0.2

Three columns have missing values. Each requires a different treatment:

  • deck (77.2% missing): The cabin deck comes from the ticket number prefix. Most third-class passengers had no assigned cabin — or records were lost. At 77% missing, there is not enough information to impute meaningfully. Drop the column.
  • age (19.9% missing): Age is a meaningful predictor. Dropping these 177 rows would shrink your training data by 20% and could introduce bias (if missingness correlates with survival). Impute with the median age.
  • embarked (0.2% missing): Only 2 passengers are missing an embarkation port. Impute with the mode — Southampton accounts for ~72% of passengers and is the safe default.

Tip

Before imputing, always check whether missingness itself carries signal. In the Titanic dataset, deck is missing for 77% of passengers and most of those are third-class. A deck_known binary flag (1 if deck is not null, 0 if it is) can capture this pattern even after you drop deck itself.

Business Context

The RMS Titanic sank on 15 April 1912 after striking an iceberg in the North Atlantic. Of the 2,224 people aboard, approximately 1,517 died — a death rate of 68%. This dataset covers 891 of those passengers (the Kaggle training set).

Survival was not random. Three factors dominated outcomes:

  1. Sex: Women were evacuated first under the "women and children first" protocol. About 74% of women survived; about 19% of men survived.
  2. Class: First-class passengers had faster access to lifeboats. Survival rates: 63% (first), 47% (second), 24% (third).
  3. Age: Children were prioritised in evacuation. Passengers under 16 had a noticeably higher survival rate.

These historical facts should guide your feature engineering. The features that mattered in reality are the ones that should matter in your model. If a feature you thought would be predictive turns out to have low importance, go back and ask whether you have captured the right signal.

Info

The dataset comes from the original Kaggle Titanic competition (launched 2012), which used data compiled by encyclopaedia-titanic.org. The seaborn version is the standard training set with 891 rows. The full Kaggle competition also has a 418-row test set with no survival labels — used for leaderboard scoring.


Previous: Project Overview | Next: Exploratory Data Analysis