Statistical Hypothesis Testing (SciPy)

End-to-End Machine Learning: Titanic Survival Prediction

1 min read

Published Nov 18 2025


10
0
0
0

KerasMachine LearningMatplotlibNumPyPandasPythonscikit-learnSciPySeabornTensorFlow

EDA provides visual evidence, but statistical tests confirm whether differences are significant.




Women vs Men survival (chi-square test)

ct = pd.crosstab(titanic["sex"], titanic["survived"])
chi2, p, _, _ = stats.chi2_contingency(ct)
print("Sex vs Survival:", p)

Output:

Sex vs Survival: 1.197357062775565e-58

Result: p ≪ 0.05, meaning gender strongly affects survival statistically.






Children vs Adults survival

titanic["is_child"] = titanic["age"] < 16
ct = pd.crosstab(titanic["is_child"], titanic["survived"])
chi2, p, _, _ = stats.chi2_contingency(ct)
print("Children vs Adults:", p)

Output:

Children vs Adults: 8.005497211300109e-05

Children have meaningfully different survival outcomes.






Passenger class

ct = pd.crosstab(titanic["pclass"], titanic["survived"])
chi2, p, _, _ = stats.chi2_contingency(ct)
print("Class vs Survival:", p)

Output:

Class vs Survival: 4.549251711298793e-23

Passenger class is highly significant.






Age differences (t-test)

age_data = titanic[["survived", "age"]].dropna()
died = age_data[age_data["survived"]==0]["age"]
surv = age_data[age_data["survived"]==1]["age"]

t, p = stats.ttest_ind(died, surv, equal_var=False)
print("Age difference:", p)

Output:

Age difference: 0.04118965162586638

Age has a statistically significant association with survival, but it is not nearly as strong a predictor as sex or class.


Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact