import matplotlib.pyplot as plt
import seaborn as sns
# Group data by Sex and Survived and count the occurrences
sex_survival_counts = train_data.groupby(['Sex', 'Survived']).size().reset_index(name='Count')
# Map the Survived values to labels
sex_survival_counts['Survived'] = sex_survival_counts['Survived'].map({0: 'Deaths', 1: 'Survived'})
# Create a grouped bar plot
plt.figure(figsize=(8, 6))
sns.barplot(data=sex_survival_counts, x='Sex', y='Count', hue='Survived', palette='viridis')
plt.title('Survival and Death Counts by Sex')
plt.xlabel('Sex')
plt.ylabel('Number of Passengers')
plt.legend(title='Survival Status')
plt.show()
Explored the Titanic dataset to understand how sex influenced survival chances.
Investigated survival status separated by gender categories.
Concluded that sex is an important feature affecting survival outcomes.
Identified gender as a useful input feature for machine learning models predicting Titanic survival.