Showing posts with label Sunburst Chart. Show all posts
Showing posts with label Sunburst Chart. 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.

Thursday, August 22, 2024

Visualizing Hierarchical Relationships in the Titanic Dataset with a Sunburst Chart

You are working with the Titanic dataset and want to visualize the relationships among various categorical variables in a hierarchical structure. Specifically, you aim to display how passengers are distributed based on their class, gender, the town they embarked from, and whether they survived. You also want to represent the survival status using a color scale to easily distinguish between those who survived and those who did not.


To address this, you would create a sunburst chart, which is a type of visualization that displays hierarchical data as a series of nested rings. Each level of the hierarchy is represented by a ring, with the innermost ring representing the top level of the hierarchy.

1. **Data Preparation**: 
   - You begin by loading the Titanic dataset, which contains information about the passengers on the Titanic, including variables like passenger class, sex, embarkation town, and survival status.
   - To ensure accurate analysis, you drop any rows in the dataset that have missing values for the variables of interest (class, sex, embarkation town, and survival status).

2. **Hierarchy Definition**:
   - You define a hierarchy for the sunburst chart where the data is organized first by passenger class, then by gender, followed by the embarkation town, and finally by survival status. This means that the chart will first split the data by class, then within each class by gender, and so on.

3. **Color Encoding**:
   - You use the survival status to determine the color of each section of the sunburst chart. A color scale is applied where different shades represent whether a passenger survived or not, making it easy to visually distinguish the outcomes.

4. **Visualization**:
   - The sunburst chart is then created using a library that supports interactive plotting. This visualization allows you to explore how different categories are related and see the proportions of passengers in each category who survived or did not survive.

Finally, the sunburst chart is displayed, providing a comprehensive view of the hierarchical relationships in the Titanic dataset and the survival outcomes of passengers based on class, gender, and embarkation town.

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