A machine learning project that predicts passenger survival on the Titanic using the Titanic dataset. The project involves data preprocessing, feature engineering, and hyperparameter-tuned K-Nearest Neighbors (KNN) classification.
titanic/
├── main.py
├── Titanic-Dataset.csv
└── README.md
This project uses a supervised machine learning approach to classify passengers based on their survival status (Survived = 0 or 1). The key steps involved include:
- Handling missing values
- Encoding categorical data
- Feature engineering (e.g.,
FamilySize,IsAlone,FareBin,AgeBin) - Data normalization using MinMaxScaler
- Hyperparameter tuning with GridSearchCV
- Classification using K-Nearest Neighbors
-
Ensure you have Python 3 and pip installed.
-
Install required libraries:
pip install pandas numpy scikit-learn matplotlib seaborn
-
Run the script:
python main.py
- Classifier Used: K-Nearest Neighbors (tuned with GridSearchCV)
- Accuracy: 80.72%
| Class | Precision | Recall | F1 Score | Support |
|---|---|---|---|---|
| 0 (Did Not Survive) | 0.81 | 0.88 | 0.85 | 134 |
| 1 (Survived) | 0.79 | 0.70 | 0.74 | 89 |
| Predicted: 0 | Predicted: 1 | |
|---|---|---|
| Actual: 0 | 118 | 16 |
| Actual: 1 | 27 | 62 |
Or view it visually:
- The dataset is sourced from Kaggle Titanic Dataset.
- You can modify the model or preprocessing logic in
main.py.
Tutorial(YouTube) - Code with Josh.
