← Back to all models
Classification

Titanic Survival

Uses passenger class, sex, and age to predict whether a Titanic passenger would have survived the 1912 disaster.

Try It Yourself

Enter values below, then hit Predict to see what the model says.

Raw Dataset (original data)
PassengerIdSurvivedPclassNameSexAgeSibSpParchTicketFareCabinEmbarked
Cleaned Dataset (the version we feed to the model)
AgePclass_Second ClassPclass_Third ClassSex_MaleSurvived
The Code (how we built this model)
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score

df = pd.read_csv('titanic_original.csv')

df = df[['Pclass', 'Sex', 'Age', 'Survived']]

df = df.dropna()

df['Survived'] = df['Survived'].map({'Yes': 1, 'No': 0})
df = pd.get_dummies(df, drop_first=True)

X = df.drop('Survived', axis=1)
y = df['Survived']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

model = DecisionTreeClassifier(max_depth=5, random_state=42)
model.fit(X_train, y_train)

y_pred = model.predict(X_test)
print(accuracy_score(y_test, y_pred))
Under the Hood (how the model thinks)

This is the actual decision tree the model learned. Starting from the top, each diamond asks a yes/no question — follow True left and False right until you reach a coloured leaf, which is the final prediction.

100%
Decision Tree