skills/cv/multilabel-cooccurrence-correlation-eda/SKILL.md
For multi-label classification, compute the per-class binary correlation matrix restricted to multi-label rows and the conditional class counts given a rare anchor class — reveals label groupings the model can exploit (shared classifier heads, hierarchical loss weighting, post-hoc consistency rules)
npx skillsauth add wenmin-wu/ds-skills cv-multilabel-cooccurrence-correlation-edaInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Multi-label problems hide a label-graph: classes that always appear together, classes that mutually exclude, and classes that anchor others. A vanilla df.corr() over the indicator columns is dominated by the empty-row baseline and shows nothing. Restricting to rows with n_labels > 1, then computing correlation, surfaces real co-occurrence. Pair this with per-rare-class conditional counts (P(label_j | label_i) for each rare i) to find which common classes systematically accompany each rare one. The output of this analysis seeds feature-engineering decisions: which classes to merge into a shared head, which to weight in a hierarchical loss, which to enforce as mutually-exclusive at post-processing.
import seaborn as sns
import matplotlib.pyplot as plt
# 1) Restrict to multi-label rows and compute correlation
multi = train_labels[train_labels['number_of_targets'] > 1]
corr = multi[class_cols].corr()
sns.heatmap(corr, cmap='RdYlBu', vmin=-1, vmax=1, square=True)
plt.title('Multi-label co-occurrence correlation')
plt.show()
# 2) Conditional counts: which classes accompany a rare anchor?
def cooccur_with(anchor, df, class_cols):
sub = df[df[anchor] == 1][class_cols].sum(axis=0)
return sub[sub > 0].sort_values(ascending=False)
print(cooccur_with('Rods & rings', train_labels, class_cols))
print(cooccur_with('Microtubule ends', train_labels, class_cols))
n_labels column counting positive labels per rown_labels >= 2 for the correlation passclustermap to surface groups visuallyX, then never predict Y")clustermap not heatmap for >15 classes: hierarchical clustering surfaces the groups automatically.data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF