skills/cv/separate-pos-neg-dice-tracking/SKILL.md
Track dice score separately for positive (mask-present) and negative (empty-mask) images to avoid division distortion
npx skillsauth add wenmin-wu/ds-skills cv-separate-pos-neg-dice-trackingInstall 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.
Standard dice metric breaks on empty masks: 2|A∩B|/(|A|+|B|) = 0/0. Most datasets hack around this by adding a small epsilon, which distorts scores for negative images. A cleaner approach: track dice separately for positive and negative cases. For negative images, dice is simply 1 if the prediction is also empty, else 0. This gives interpretable per-category scores and reveals whether the model is failing on positives or leaking false positives on negatives.
import torch
def dice_metric_split(probability, truth, threshold=0.5):
"""Return (all_dice, dice_neg, dice_pos) — dice split by mask presence."""
with torch.no_grad():
p = (probability > threshold).float().view(len(truth), -1)
t = (truth > 0.5).float().view(len(truth), -1)
t_sum = t.sum(-1)
p_sum = p.sum(-1)
neg_idx = torch.nonzero(t_sum == 0).squeeze(-1)
pos_idx = torch.nonzero(t_sum >= 1).squeeze(-1)
# Negative: 1 if prediction is also empty, else 0
dice_neg = (p_sum == 0).float()
# Positive: standard dice
dice_pos = 2 * (p * t).sum(-1) / ((p + t).sum(-1) + 1e-7)
dice_neg = dice_neg[neg_idx]
dice_pos = dice_pos[pos_idx]
return torch.cat([dice_pos, dice_neg]), dice_neg, dice_pos
dice_neg drops, model is hallucinating masks on healthy images — add a classification gate. If dice_pos drops, improve segmentation directly.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