skills/tabular/logit-transform-stacking/SKILL.md
Applies logit transformation to base model probabilities before fitting a logistic regression meta-learner, enabling principled linear combination in log-odds space.
npx skillsauth add wenmin-wu/ds-skills tabular-logit-transform-stackingInstall 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 stacking binary classification models, the base model outputs are probabilities in [0, 1]. Fitting a linear meta-learner directly on probabilities is suboptimal because the relationship between probabilities and log-odds is nonlinear — a 0.01 difference near 0.5 means less than near 0.99. Applying logit (log(p/(1-p))) transforms probabilities to log-odds space where linear combination is theoretically justified. The logistic regression meta-learner then learns optimal weights in this space, often outperforming probability-space blending by 0.001–0.003 AUC.
import numpy as np
import pandas as pd
from scipy.special import logit, expit
from sklearn.linear_model import LogisticRegression
ALMOST_ZERO = 1e-10
ALMOST_ONE = 1 - ALMOST_ZERO
# Load OOF predictions from base models
oof_preds = {}
for name, path in base_model_files.items():
probs = pd.read_csv(path)['prediction']
oof_preds[name] = logit(probs.clip(ALMOST_ZERO, ALMOST_ONE))
X_train = pd.DataFrame(oof_preds).values
y_train = true_labels
# Fit meta-learner in logit space
meta = LogisticRegression(C=1.0)
meta.fit(X_train, y_train)
# Inspect learned weights
weights = meta.coef_[0] / meta.coef_[0].sum()
print("Model weights:", dict(zip(oof_preds.keys(), weights)))
# Apply to test predictions
test_preds = {}
for name, path in test_model_files.items():
probs = pd.read_csv(path)['prediction']
test_preds[name] = logit(probs.clip(ALMOST_ZERO, ALMOST_ONE))
X_test = pd.DataFrame(test_preds).values
final_probs = meta.predict_proba(X_test)[:, 1]
[1e-10, 1-1e-10] to avoid infinite logit valueslogit() transform to all base model outputsLogisticRegression on logit-transformed OOF predictions[1e-10, 1-1e-10]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