skills/nlp/optuna-ensemble-weights/SKILL.md
Learns optimal per-model blending weights via Optuna optimization, supporting negative weights for error cancellation.
npx skillsauth add wenmin-wu/ds-skills nlp-optuna-ensemble-weightsInstall 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.
Instead of equal-weight averaging across models, use Optuna to search for optimal per-model weights that minimize the validation metric. Weights can be negative — allowing error cancellation between correlated models. Optimize separately per target when targets have different optimal blends.
import optuna
import numpy as np
def optimize_weights(predictions, labels, n_models, target_name):
def objective(trial):
weights = [trial.suggest_float(f"w{i}", -0.5, 1.0) for i in range(n_models)]
blended = np.stack([p * w for p, w in zip(predictions, weights)]).sum(0)
rmse = np.sqrt(np.mean((blended - labels) ** 2))
return rmse
study = optuna.create_study(direction="minimize")
study.optimize(objective, n_trials=200, show_progress_bar=False)
return [study.best_params[f"w{i}"] for i in range(n_models)]
# Per-target optimization
content_weights = optimize_weights(content_preds, content_labels, 4, "content")
wording_weights = optimize_weights(wording_preds, wording_labels, 4, "wording")
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