Interactive Sankey diagram widget for topic modeling analysis with sample flow tracing
Project description
Stripe Sankey Widget
An interactive Sankey diagram widget for understanding how samples are represented by topics across different LDA models. This tool can also be applied to similar algorithms like NMF and LSA.
LDA is a powerful tool for achieving soft clustering and finding latent groups beyond initial hypotheses. However, the challenge of applying LDA to 16S rRNA data is that sequence reads are less informative than human language when users want to evaluate a model's results. Even when metrics are applied, making decisions remains difficult.
We designed this StripeSankey diagram to make LDA results more accessible and integrated two widely used metrics—perplexity and coherence score—into novel visual encodings.
Overview of StripeSankey diagram:
Legend of metrics coour:
After click one flow:
Installation
From PyPI
pip install StripeSankey
Data Preprocessing
Quick Start
import stripe_sankey
from stripe_sankey import StripeSankeyInline
# Load your processed topic modeling data
sankey_data = {
"nodes": {
"K2_MC1": {
"high_count": 45,
"medium_count": 23,
"model_metrics": {"perplexity": 1.2},
"mallet_diagnostics": {"coherence": -0.15}
},
# ... more nodes
},
"flows": [
{
"source_segment": "K2_MC1_high",
"target_segment": "K3_MC2_medium",
"source_k": 2,
"target_k": 3,
"sample_count": 15,
"samples": [{"sample": "doc_1", "source_prob": 0.8, "target_prob": 0.6}]
},
# ... more flows
],
"k_range": [2, 3, 4, 5]
}
# Create and display widget
widget = StripeSankeyInline(sankey_data=sankey_data)
widget
Visualization Modes
Default Mode
Shows topic representations with high/medium probability segments:
widget = StripeSankeyInline(sankey_data=data, mode="default")
Metric Mode
Color-codes topics by quality metrics (perplexity + coherence):
widget = StripeSankeyInline(sankey_data=data, mode="metric")
# Customize metric weights
widget.update_metric_config(red_weight=0.9, blue_weight=0.7)
Interactive Features
Sample Flow Tracing
- Click any flow to highlight sample trajectories across K values
- Orange trajectories show where samples move between topics
- Count badges display number of traced samples in each segment
- Line thickness represents sample flow volume
- Click background to clear selection
Visual Elements
- Stacked bars: High (dark) and medium (light) probability representations
- Curved flows: Proportional thickness based on sample counts
- Barycenter layout: Optimized positioning to reduce visual complexity
- Hover tooltips: Detailed information on flows and segments
Data Format
Your data should follow this structure:
{
"nodes": {
"K{k}_MC{mc}": {
"high_count": int, # Samples with prob ≥ 0.67
"medium_count": int, # Samples with prob 0.33-0.66
"total_probability": float,
"model_metrics": {
"perplexity": float # Lower is better
},
"mallet_diagnostics": {
"coherence": float # Higher (less negative) is better
}
}
},
"flows": [
{
"source_segment": "K{k}_MC{mc}_{level}",
"target_segment": "K{k+1}_MC{mc}_{level}",
"source_k": int,
"target_k": int,
"sample_count": int,
"average_probability": float,
"samples": [
{
"sample": str, # Sample identifier
"source_prob": float, # Probability in source topic
"target_prob": float # Probability in target topic
}
]
}
],
"k_range": [2, 3, 4, 5] # Topic numbers analyzed
}
Configuration Options
Widget Parameters
widget = StripeSankeyInline(
sankey_data=data,
width=1200, # Canvas width
height=800, # Canvas height
mode="default" # "default" or "metric"
)
Metric Mode Configuration
widget.update_metric_config(
red_weight=0.8, # Perplexity influence (0-1)
blue_weight=0.8, # Coherence influence (0-1)
min_saturation=0.3 # Minimum color brightness
)
Color Schemes
widget.color_schemes = {
2: "#1f77b4", # Blue for K=2
3: "#ff7f0e", # Orange for K=3
4: "#2ca02c", # Green for K=4
5: "#d62728" # Red for K=5
}
Use Cases
- Topic Model Analysis: Understand how topics evolve across different K values
- Sample Trajectory Tracking: Follow samples through topic assignments
- Model Quality Assessment: Visual comparison of perplexity and coherence metrics
- Flow Bottleneck Detection: Identify where samples cluster or disperse
- Research Presentation: Interactive demonstrations of topic modeling results
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stripesankey-0.3.0.tar.gz.
File metadata
- Download URL: stripesankey-0.3.0.tar.gz
- Upload date:
- Size: 5.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
656e2aa4e9258cfa0122e6c564d6686a706aa03275dd12041f732cc38d1aa7da
|
|
| MD5 |
984f468e459c61f24c9c6e3f113d5838
|
|
| BLAKE2b-256 |
ea9fb85b5a61c938ab04eac97e32d93a0c1d6f48ec456fcd494c234838df8b7e
|
File details
Details for the file stripesankey-0.3.0-py3-none-any.whl.
File metadata
- Download URL: stripesankey-0.3.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74c76e0a22c9393fbed30a5a721c71a1685c889293f848176d292a26d6307579
|
|
| MD5 |
00f78cbe3cd12e2d47854fe647bb1fd6
|
|
| BLAKE2b-256 |
448a9b0e1abc5f63877ca13de3c894854d0f1e8c06f837846dc8525cd44a0337
|