skills/cv/iou-threshold-sweep/SKILL.md
Grid search binarization thresholds on validation predictions to find the cutoff that maximizes mean IoU
npx skillsauth add wenmin-wu/ds-skills cv-iou-threshold-sweepInstall 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.
Segmentation models output continuous probability maps but metrics require binary masks. The default 0.5 threshold is often suboptimal — shifting it can improve IoU by several points with zero cost. This technique sweeps a dense grid of thresholds over the validation set, measures mean IoU at each, and picks the best one as the final binarization cutoff.
import numpy as np
def iou_metric_batch(y_true, y_pred_binary):
batch = y_true.shape[0]
return np.mean([iou_metric(y_true[i], y_pred_binary[i]) for i in range(batch)])
# Sweep thresholds
thresholds = np.linspace(0.2, 0.9, 31)
ious = np.array([
iou_metric_batch(y_valid, (preds_valid > t).astype(np.int32))
for t in thresholds
])
best_idx = np.argmax(ious)
best_threshold = thresholds[best_idx]
best_iou = ious[best_idx]
print(f"Best threshold: {best_threshold:.3f} → IoU: {best_iou:.4f}")
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