skills/cv/per-class-score-threshold/SKILL.md
Apply class-specific confidence thresholds by inferring the dominant class per image and indexing into a per-class threshold array
npx skillsauth add wenmin-wu/ds-skills cv-per-class-score-thresholdInstall 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.
Different object classes have different score distributions — small dense cells score lower than large isolated ones. A single global threshold under-filters easy classes and over-filters hard ones. Infer the dominant class per image (mode of predicted classes), then apply that class's optimized threshold. Common in cell segmentation where cell types have very different morphologies.
import torch
import numpy as np
THRESHOLDS = [0.15, 0.35, 0.55] # per class, tuned on validation
MIN_PIXELS = [75, 150, 75] # per class minimum area
def filter_predictions(predictions):
scores = predictions['scores']
classes = predictions['pred_classes']
masks = predictions['pred_masks']
# Infer dominant class for this image
dominant_class = torch.mode(classes)[0].item()
# Apply class-specific threshold
keep = scores >= THRESHOLDS[dominant_class]
return masks[keep], scores[keep], dominant_class
masks, scores, cls = filter_predictions(output['instances'])
torch.mode is simple; for mixed-class images, consider per-instance thresholds insteaddata-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