skills/tabular/log-odds-fold-averaging/SKILL.md
Average model predictions across CV folds in log-odds space rather than probability space for better-calibrated ensemble outputs
npx skillsauth add wenmin-wu/ds-skills tabular-log-odds-fold-averagingInstall 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.
When averaging predictions across CV folds, work in log-odds (logit) space instead of probability space. Log-odds averaging preserves the natural scale of the model's raw output and produces better-calibrated probabilities after inverse-logit transform. Especially effective for gradient boosting models that output raw log-odds by default.
import numpy as np
def log_odds_average(fold_predictions, from_proba=False):
"""Average predictions in log-odds space.
Args:
fold_predictions: list of arrays, one per fold
from_proba: if True, convert probabilities to log-odds first
"""
if from_proba:
eps = 1e-7
fold_predictions = [
np.log(np.clip(p, eps, 1-eps) / (1 - np.clip(p, eps, 1-eps)))
for p in fold_predictions
]
avg_logits = np.mean(fold_predictions, axis=0)
# Return raw log-odds (for ranking) or convert to probability
return avg_logits # or: 1 / (1 + np.exp(-avg_logits))
# With LightGBM: collect raw_score directly
fold_preds = []
for fold_model in models:
raw = fold_model.predict(X_test, raw_score=True) # log-odds
fold_preds.append(raw)
final = log_odds_average(fold_preds)
predict(raw_score=True) returns log-odds directlydata-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