Predicting passenger survival using an end-to-end machine learning classification pipeline built on Kaggle's Titanic: Machine Learning from Disaster dataset.
This project predicts whether a passenger survived the Titanic disaster using demographic and travel-related information such as age, sex, passenger class, fare, and family relationships.
The project follows a complete machine learning workflow—from exploratory data analysis and feature engineering to model training, hyperparameter tuning, and generating a Kaggle-ready submission. Every major preprocessing and modeling decision is carefully evaluated to understand its impact on predictive performance and generalization.
Dataset: Kaggle — Titanic: Machine Learning from Disaster
- Data Overview
- Missing Value Analysis
- Exploratory Data Analysis (EDA)
- Data Cleaning
- Feature Engineering
- Encoding & Preprocessing
- Model Training
- Model Evaluation
- Hyperparameter Tuning
- Kaggle Submission
The dataset contains 891 training samples with 12 original features.
The following preprocessing steps were performed:
| Step | Description |
|---|---|
Missing Age values |
Imputed using the median age within each passenger title (Mr, Mrs, Miss, Master, etc.) |
Missing Embarked values |
Filled using the mode |
Missing Fare values |
Filled using the median fare |
Cabin |
Dropped because over 75% of the values were missing |
Name |
Used to extract passenger titles before being removed |
Ticket |
Removed due to high cardinality and limited predictive value |
PassengerId |
Retained only for generating the final Kaggle submission |
No duplicate records were found.
- Female passengers had a significantly higher survival rate than male passengers.
- First-class passengers were considerably more likely to survive than passengers in lower classes.
- Younger passengers generally had higher survival rates.
- Passengers travelling alone were less likely to survive than those travelling with family members.
- Higher ticket fares were positively associated with survival, largely because they corresponded to higher passenger classes.
| Feature | Formula / Description | Purpose |
|---|---|---|
| Title | Extracted from passenger names | Captures age group and social status |
| FamilySize | SibSp + Parch + 1 |
Represents the total number of family members travelling together |
| IsAlone | Derived from FamilySize |
Indicates whether a passenger travelled alone |
- Missing values were handled before model training.
- One-Hot Encoding was applied to categorical variables.
- Numerical features were standardized using StandardScaler where required.
- Tree-based models were trained without relying on feature scaling.
| Model | Accuracy | Precision | Recall | F1 Score |
|---|---|---|---|---|
| Logistic Regression | 80.45% | 76.00% | 77.03% | 76.51% |
| Decision Tree | 79.89% | 76.39% | 74.32% | 75.34% |
| Random Forest | 84.92% | 82.19% | 81.08% | 81.63% |
| Gradient Boosting | 82.68% | 82.09% | 74.32% | 78.01% |
| K-Nearest Neighbors (KNN) | 81.56% | 76.62% | 79.73% | 78.15% |
The Decision Tree severely overfit the training data, achieving 98.03% training accuracy but only 79.89% test accuracy. Ensemble methods produced much better generalization, with Random Forest delivering the strongest performance before hyperparameter tuning.
Hyperparameter tuning was performed using GridSearchCV.
| Model | Original Accuracy | Tuned Accuracy |
|---|---|---|
| Logistic Regression | 80.45% | 81.01% |
| Random Forest | 84.92% | 82.12% |
| Gradient Boosting | 82.68% | 83.24% |
| K-Nearest Neighbors (KNN) | 81.56% | 81.56% |
- Logistic Regression improved slightly while maintaining excellent generalization.
- Random Forest significantly reduced overfitting, although it sacrificed some predictive performance.
- Gradient Boosting improved both accuracy and generalization after tuning.
- KNN maintained the same overall accuracy but shifted the balance between Precision and Recall.
Among the tuned models, Gradient Boosting achieved the strongest balance between predictive performance and generalization.
- Accuracy: 83.24%
- Precision: 80.56%
- Recall: 78.38%
- F1 Score: 79.45%
- Train-Test Accuracy Gap: 5.95%
Although the untuned Random Forest achieved the highest raw test accuracy (84.92%), the tuned Gradient Boosting classifier provided the best balance between predictive performance and generalization, making it the final model selected for this project.
- Passenger class and gender were the strongest predictors of survival.
- Feature engineering using passenger titles and family-related features improved classification performance.
- Ensemble learning methods consistently outperformed individual Decision Trees.
- Monitoring the train-test accuracy gap was essential for identifying overfitting.
- Hyperparameter tuning improved model robustness even when it did not always increase raw accuracy.
- Evaluate models using k-fold cross-validation.
- Experiment with XGBoost, LightGBM, and CatBoost.
- Apply feature selection to remove redundant features.
- Optimize classification thresholds instead of using the default 0.5 probability cutoff.
- Explore ensemble techniques such as Voting and Stacking classifiers.
Python · Pandas · NumPy · Matplotlib · Seaborn · scikit-learn
titanic-survival-prediction/
│
├── data/
│ ├── train.csv
│ ├── test.csv
│ └── submission.csv
│
├── notebooks/
│ └── titanic-survival-prediction.ipynb
│
├── .gitignore
├── README.md
└── requirements.txt
git clone https://github.com/kushwahaaa27/titanic-survival-prediction.git
cd titanic-survival-prediction
pip install pandas numpy matplotlib seaborn scikit-learn
jupyter notebook notebooks/titanic-survival-prediction.ipynbIf you have any suggestions or notice something that could be improved, feel free to open an issue or share your feedback.
Arpit Kushwaha (@kushwahaaa27)