User Guide
Introduction
mheatmap is a Python package for advanced heatmap visualization and matrix analysis.
It provides tools for:
- Creating proportional/mosaic heatmaps
- AMC post-processing of confusion matrices
- Spectral permutation analysis
- RMS (Reverse Merge/Split) permutation analysis
Basic Usage
Mosaic Heatmap
The mosaic heatmap is a novel visualization where cell sizes are proportional to their row and column sums:
- Show values in cells
- Format as integers
- Use Yellow-Orange-Red colormap
AMC Post-processing
AMC (Align-Mask-Confusion) is a technique for post-processing confusion matrices or to say pre-processing before mosaic heatmap visualization:
\[
C_{masked} = C_{raw} \odot M, \quad
\text{where } \odot \text{ is the element-wise multiplication}
\]
\[
\Pi = \underset{\pi}{\arg\min} \sum_{i,j} C_{masked}[i,\Pi(j)], \quad
\text{where } \Pi \text{ is a permutation matrix}
\]
\[
\tilde{y} = \Pi \cdot \hat{y}
\]
\[
\tilde{C} = \Pi \cdot C_{masked}
\]
\[
\tilde{l} = \Pi \cdot l
\]
Spectral Reordering
Reorder matrices based on spectral analysis:
Note: see examples
for more details.
RMS Permutation Analysis
RMS (Reverse Merge/Split) analysis helps identify merge and split relationships in matrices:
Note: see examples
for more details.
Tips and Tricks
Memory Efficiency
For large matrices:
- Use sparse matrices for efficiency
Performance Tips
- Use
numpy
arrays instead of lists - Pre-compute reusable values
- Use sparse matrices for large, sparse data
- Consider downsampling for visualization of very large matrices