This Flask web application predicts the probability of survival for passengers on the Titanic using machine learning.
-
Clone this repository:
git clone https://github.com/MahmoudMohajer/Titanic_survival_project.git cd Titanic_survival_project
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows, use: venv\Scripts\activate
-
Install the required packages:
pip install -r requirements.txt
-
Run the Flask app:
python app.py
-
Open a web browser and go to
http://localhost:5000
. -
Fill in the passenger details in the form:
- Pclass: Passenger class (1, 2, or 3)
- Sex: Male or Female
- Age: Age in years
- SibSp: Number of siblings/spouses aboard
- Parch: Number of parents/children aboard
- Fare: Passenger fare
- Embarked: Port of embarkation (C = Cherbourg, Q = Queenstown, S = Southampton)
-
Click the "Predict" button to see the survival probability.
- Web interface for easy input of passenger details
- Real-time prediction using a trained machine learning model
- Displays both the binary survival prediction and the probability of survival
The prediction model used in this app is a machine learning classifier trained on the Titanic dataset. The model considers various features such as passenger class, sex, age, and family size to make predictions.
The model was trained using the following process:
-
Data preprocessing:
- Handling missing values
- Converting categorical variables to numerical
- Feature engineering (e.g., creating 'FamilySize', 'IsAlone', and 'Age*Class' features)
-
Feature selection:
- Selected features: 'Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare', 'Embarked'
-
Model selection:
- Compared Random Forest and Gradient Boosting Classifiers
- Used GridSearchCV for hyperparameter tuning
-
Evaluation:
- Used cross-validation and a separate validation set to assess model performance
- Evaluated using accuracy, classification report, and confusion matrix
The best performing model was saved and is used in this application for making predictions. you can find the model training code in kaggle notebook
Contributions to improve the app are welcome. Please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Make your changes and commit them (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature-branch
) - Create a new Pull Request
This project is licensed under the GPL 3.0 License - see the LICENSE.md file for details.