Machine Learning / Python · Learning project
Titanic Survival Prediction — Logistic Regression
A Python logistic regression model on the Kaggle Titanic dataset — exploring which passenger features predicted survival, and achieving 77% test accuracy on a held-out test set.
- Status
- Published
- Published
- January 2023
- Reading time
- 4 min read
- Project type
- Python & ML
- Complexity
- Low
77% on held-out test set
Model accuracy
Kaggle Titanic — passenger survival classification
Dataset
Python end to end — data loading to confusion matrix
Stack
Business Question
Can passenger characteristics — class, age, gender, fare, embarkation port — predict survival on the Titanic? This is a standard binary classification problem that served as the first full end-to-end ML pipeline I built in Python.
Data Sources
The Kaggle Titanic dataset: 891 training records with features including passenger class, name, sex, age, number of siblings/spouses aboard, number of parents/children aboard, ticket number, fare, cabin number and port of embarkation — and a binary survival target.
Approach
A complete Python workflow: data loading, exploratory visualization, null handling, feature selection, train/test split (scikit-learn), logistic regression model fit, predictions and evaluation via confusion matrix and accuracy score.
Key Steps
- Data exploration — countplots (survival by sex, by class), histograms (age distribution, fare distribution) using seaborn and matplotlib to understand the data before modelling
- Data cleaning — isnull() checks, dropping columns with high null rates (cabin), imputing where appropriate
- Feature engineering — defining X (independent variables: passenger class, sex, age, fare, siblings, parents) and y (survival)
- Modelling — train/test split, LogisticRegression() fit, predictions on the test set
- Evaluation — confusion matrix showing 102 + 63 correct predictions and 24 + 25 incorrect; accuracy score of 77%
The notebook below recreates the actual pipeline — cell by cell, code through to the confusion matrix.
(891, 12)
Cabin 687 Age 177 Embarked 2 Fare 0 Ticket 0 dtype: int64
LogisticRegression(max_iter=1000)
[[102 25] [ 24 63]] Accuracy: 0.771
Key Finding
Fare contributed more to predicted survival than other variables based on the model coefficients — a result that reflects the class structure on the ship. Gender and class were also significant predictors, consistent with the historical "women and children first" evacuation pattern.
Technologies I Personally Used
Python
Modelling
Lessons Learned
- The confusion matrix is more informative than accuracy alone — 77% accuracy looks reasonable but the matrix shows where the model fails (false negatives vs false positives) and which error type matters more in context
- Feature selection before modelling matters: including passenger name and ticket number adds noise without predictive value
- This was a first Python ML project, built collaboratively with a teammate; the process of explaining each step (in the LinkedIn post we published) reinforced the concepts more than just running the code did
Reflection
What I learned: the whole pipeline from import pandas to a confusion matrix — and that the interesting part isn't fitting the model, it's understanding why the model makes the predictions it does.
What I would improve today: feature engineering (extracting titles from names, family size from siblings+parents), hyperparameter tuning, and comparing logistic regression against a decision tree and random forest for the same dataset.
Published: January 2023, with teammate Amarjeet Singh, with guidance from senior Abhimanyu Kr.
Related work
R&D & Marketing Intelligence
News & Tender Intelligence Portal
An internal intelligence portal that automates news and tender monitoring for R&D and Marketing, replacing fragmented manual searches with a centralized, keyword-driven workflow.
Field Operations & Supply Chain
Seaweed Digital Platform
A mobile-first field platform digitizing seaweed collection operations across 30+ coastal sites — offline-first collection capture, field hierarchy, species-wise targets and daily operational visibility. Vendor-developed; I own it functionally end to end.