skills/tabular/per-fold-threshold-voting-ensemble/SKILL.md
Binarizes each CV fold's predictions using its own optimized threshold, then majority-votes across folds instead of averaging raw probabilities.
npx skillsauth add wenmin-wu/ds-skills tabular-per-fold-threshold-voting-ensembleInstall 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 ensembling averages probabilities across folds, then applies a single global threshold. This assumes all folds are calibrated equally — which they often aren't, especially with class imbalance or varying fold distributions. Per-fold threshold voting first optimizes a binary threshold per fold (e.g., via F1 or IoU on validation), binarizes each fold's predictions independently, then takes a majority vote. This is more robust to miscalibrated folds.
import numpy as np
def per_fold_vote(fold_preds, fold_thresholds):
"""Majority vote after per-fold binarization.
Args:
fold_preds: list of arrays, each (N,) with probabilities
fold_thresholds: list of floats, one threshold per fold
Returns:
(N,) binary predictions
"""
binary_preds = [
(pred >= thresh).astype(int)
for pred, thresh in zip(fold_preds, fold_thresholds)
]
# Majority vote: >= 0.5 of folds predict positive
votes = np.mean(binary_preds, axis=0)
return (votes >= 0.5).astype(int)
# Thresholds tuned per fold during CV
thresholds = [0.42, 0.45, 0.38, 0.44, 0.41]
final_preds = per_fold_vote(test_fold_preds, thresholds)
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