Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Titanic Survival Prediction (Interpretable ML + Model Comparison)

A small, portfolio-ready machine learning project using the Titanic dataset.
The focus is interpretability + correct evaluation, not just accuracy.

What I tested (hypotheses)

Before modeling, I started with these assumptions:

  • Women survived more than men
  • Higher class → higher survival
  • Younger passengers → higher survival
  • Higher fare → higher survival (as a proxy for wealth)

Then I trained models to validate/refine those hypotheses with data.


Dataset

  • File: Titanic-Dataset.csv
  • Common Kaggle-style Titanic dataset used for ML practice.

Approach

1) Preprocessing

  • Fill missing values:
    • Age → median
    • Embarked → mode
  • Drop Cabin (too many missing values)
  • Encode categorical variables:
    • Sex → binary (male=1, female=0)
    • Embarked → one-hot encoding with drop_first=True
      (baseline category becomes Embarked_C)

2) Model 1 — Logistic Regression (primary)

  • Trained Logistic Regression for probability-based predictions: [ P(\text{Survived}=1 \mid X) ]
  • Evaluated using:
    • Accuracy
    • Precision
    • Recall
    • F1
    • Confusion Matrix

3) Threshold tuning

  • Default predict() uses threshold = 0.5
  • I also tested threshold = 0.4 using predict_proba():
    • Improves recall and often F1 (tradeoff: more false positives)

4) Explainability

  • Printed coefficients (log-odds)
  • Converted coefficients → odds ratios
  • Added:
    • % Change in Odds
    • Odds as % of Baseline

5) Model 2 — Random Forest (comparison)

  • Trained RandomForestClassifier on the same features
  • Compared metrics at:
    • default voting threshold
    • threshold = 0.4 (using probabilities)

Key insights (from Logistic Regression odds ratios)

  • Sex and Pclass were the strongest predictors.
  • Age and family-related features (SibSp/Parch) were secondary.
  • Fare had minimal independent effect once class was included (often redundant with Pclass).

Summary conclusion:

“Survival was driven primarily by gender and class; age and family structure played secondary roles, while fare added little independent signal once class was accounted for.”


Project structure (suggested)

. ├── Titanic-Dataset.csv ├── titanic_model.py ├── README.md ├── requirements.txt └── LICENSE

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages