CodSoft Data Science Internship โ€ข Task 1

Titanic Survival
Prediction

A complete Machine Learning pipeline โ€” from raw data to trained model โ€” that predicts passenger survival on the RMS Titanic using 6 classification algorithms with hyperparameter tuning.

Python 3.11+ Scikit-Learn Pandas Matplotlib Seaborn NumPy

891

Passengers

6

ML Models

7

Engineered Features

13+

Visualizations

Project Overview

Understanding the business problem and dataset

๐ŸŽฏ

Business Problem

The sinking of the RMS Titanic on April 15, 1912, killed more than 1,500 of the 2,224 passengers and crew. This project builds a binary classification model to predict: Did a passenger survive?

By analyzing factors like passenger class, gender, age, fare, and family size, we can understand what made certain groups more likely to survive.

๐Ÿ“Š

Dataset

Source Kaggle (yasserh)
Rows 891
Columns 12
Target Survived
Task Binary Classification
Survival Rate 38.4%
๐Ÿ“‹

Dataset Features

Column Type Description Missing

ML Pipeline

End-to-end workflow executed by python main.py

๐Ÿงน Data Preprocessing

โœ“
Age โ€” Median imputation grouped by Pclass & Sex
โœ“
Embarked โ€” Mode imputation (Southampton)
โœ“
Cabin โ€” Binary flag (CabinAvailable)
โœ“
Sex โ€” Label Encoding (binary)
โœ“
Embarked โ€” One-Hot Encoding (3 categories)
โœ“
Features โ€” StandardScaler normalization

โš™๏ธ Feature Engineering

Project Structure

Complete file organization

Models & Evaluation

6 classification algorithms trained and compared

๐Ÿ“ Evaluation Metrics Explained

๐Ÿ”ง Hyperparameter Tuning

GridSearchCV with 5-fold cross-validation is performed on the top 2 models. The search explores combinations of hyperparameters to find the optimal configuration that maximizes accuracy.

Random Forest Search Space

n_estimators: [100, 200, 300]
max_depth: [5, 10, 15, None]
min_samples_split: [2, 5]
min_samples_leaf: [1, 2]

Gradient Boosting Search Space

n_estimators: [100, 200, 300]
learning_rate: [0.01, 0.05, 0.1]
max_depth: [3, 5, 7]
min_samples_split: [2, 5]

Code Preview

Key source files from the project

Output Artifacts

All generated files saved in the outputs/ directory

๐Ÿ“Š model_comparison.csv

Performance table comparing all 6 models across Train Accuracy, Test Accuracy, CV Mean, and CV Std.

๐Ÿ“ˆ predictions.csv

Test set predictions with actual labels, predicted labels, survival probabilities, and correctness flags.

๐Ÿค– titanic_model.pkl

Serialized best model saved with Joblib for reuse and inference without retraining.

Generated Visualizations (13 plots)

How to Run

Step-by-step instructions

1

Clone & Setup

git clone https://github.com/yourusername/Titanic_Survival_Prediction.git
cd Titanic_Survival_Prediction
python -m venv venv
source venv/bin/activate  # or venv\Scripts\activate on Windows
pip install -r requirements.txt
2

Download Dataset

Download from Kaggle and place Titanic-Dataset.csv in the dataset/ folder.

3

Run the Pipeline

python main.py

This executes the complete ML pipeline automatically.

4

Or Run Notebook

cd notebook
jupyter notebook Titanic_Survival_Prediction.ipynb

โšก What python main.py does