Showing posts with label plotly express. Show all posts
Showing posts with label plotly express. Show all posts

Saturday, January 11, 2025

Visualizing Titanic Survival Patterns with a Sunburst Chart

Titanic Dataset Sunburst Visualization – Complete Guide

๐Ÿšข Titanic Dataset Visualization Using Sunburst Chart

The Titanic dataset is one of the most widely used datasets in data science. In this guide, we’ll explore how to visualize it using a sunburst chart—a powerful way to understand hierarchical relationships.


๐Ÿ“š Table of Contents


๐Ÿ“Š Dataset Overview

ColumnDescription
classPassenger class (1st, 2nd, 3rd)
sexGender
embark_townBoarding location
survived0 = No, 1 = Yes

๐ŸŒž What is a Sunburst Chart?

A sunburst chart shows hierarchical relationships using concentric circles.

Outer layer → Class Next → Gender Next → Embark Town Inner → Survival

๐Ÿ“ Math Behind the Visualization (Simple)

1. Probability of Survival

\[ P(Survival | Class) = \frac{\text{Survivors in Class}}{\text{Total Passengers in Class}} \]

This tells us survival likelihood for each class.

2. Conditional Probability

\[ P(Survival | Class, Gender) = \frac{\text{Survivors in Group}}{\text{Total in Group}} \]

๐Ÿ‘‰ Example: “What is the survival rate of females in 1st class?”

3. Hierarchical Contribution

\[ Total = \sum_{i} Group_i \]

Each segment size is proportional to its count.


⚙️ Steps to Create Sunburst Chart

  1. Clean dataset
  2. Select relevant columns
  3. Define hierarchy
  4. Generate visualization

๐Ÿ’ป Code Example

import plotly.express as px import pandas as pd df = px.data.titanic() df = df.dropna(subset=['class','sex','embark_town','survived']) fig = px.sunburst( df, path=['class','sex','embark_town','survived'], color='survived', color_continuous_scale='RdBu' ) fig.show()

๐Ÿ–ฅ️ Output

Click to View
Sunburst chart generated successfully.
Interactive visualization opens in browser.

๐Ÿ” Key Insights

  • 1st class passengers had higher survival rates
  • Women survived more than men
  • Cherbourg passengers had slightly better survival
Green = Survived Red = Did Not Survive

๐Ÿ’ก Key Takeaways

  • Sunburst charts simplify complex relationships
  • Hierarchy reveals deeper insights
  • Probability helps interpret visual segments

๐ŸŽฏ Final Thoughts

The sunburst chart transforms raw Titanic data into a meaningful story. It shows not just who survived—but why patterns exist across different groups.

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts