Loading the Titanic Dataset

End-to-End Machine Learning: Titanic Survival Prediction

1 min read

Published Nov 18 2025, updated Aug 17 2026


10
0
0
0

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) $




Install all the libraries

pip install numpy pandas seaborn matplotlib scipy scikit-learn tensorflow




Import all the libraries needed and load the dataset:

import numpy as npimport pandas as pdimport seaborn as snsimport matplotlib.pyplot as plt​from scipy import stats​from sklearn.model_selection import train_test_splitfrom sklearn.preprocessing import OneHotEncoder, StandardScalerfrom sklearn.compose import ColumnTransformerfrom sklearn.pipeline import Pipelinefrom sklearn.metrics import (    accuracy_score,    classification_report,    confusion_matrix,    roc_auc_score,    RocCurveDisplay,    roc_curve,)​from sklearn.linear_model import LogisticRegressionfrom sklearn.ensemble import RandomForestClassifier​import tensorflow as tffrom tensorflow.keras import layers, models, callbacks​sns.set(style="whitegrid")RANDOM_STATE = 42​# Load datasettitanic = sns.load_dataset("titanic")print(titanic.head())

The dataset includes both numeric and categorical columns, with survived being our prediction target.

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact