Loading the Titanic Dataset
End-to-End Machine Learning: Titanic Survival Prediction
1 min read
This section is 1 min read, full guide is 12 min read
Published Nov 18 2025
10
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
KerasMachine LearningMatplotlibNumPyPandasPythonscikit-learnSciPySeabornTensorFlow
We begin by importing all required libraries and loading the Seaborn Titanic dataset, which provides cleaned but rich information: passenger demographics, ticket class, fares, and survival outcome.
Setup the virtual environment
# Create a virtual environment called '.venv'
python3 -m venv .venv
# Activate it (Linux/macOS)
source .venv/bin/activate
# or activate it (Windows CMD)
.venv\Scripts\activate
# or activate it (Windows PowerShell)
.\.venv\Scripts\Activate.ps1
# Your shell prompt should change to indicate the environment is active
# e.g., (.venv) $
Copy to Clipboard
Toggle show comments
Install all the libraries
pip install numpy pandas seaborn matplotlib scipy scikit-learn tensorflow
Copy to Clipboard
Import all the libraries needed and load the dataset:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from scipy import stats
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.metrics import (
accuracy_score,
classification_report,
confusion_matrix,
roc_auc_score,
RocCurveDisplay,
roc_curve,
)
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
import tensorflow as tf
from tensorflow.keras import layers, models, callbacks
sns.set(style="whitegrid")
RANDOM_STATE = 42
# Load dataset
titanic = sns.load_dataset("titanic")
print(titanic.head())
Copy to Clipboard
Toggle show comments
The dataset includes both numeric and categorical columns, with survived being our prediction target.














