skills/tabular/balanced-log-loss/SKILL.md
Class-balanced log loss that weights each class by the inverse of its sample count, equalizing the contribution of minority and majority classes.
npx skillsauth add wenmin-wu/ds-skills tabular-balanced-log-lossInstall 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 log loss is dominated by the majority class — in a 90/10 split, the loss is 90% driven by class-0 predictions. Balanced log loss weights each class by 1/N_class, equalizing their contribution regardless of sample count. This is the correct metric when false negatives on the minority class are as costly as false positives on the majority class. Many Kaggle competitions with imbalanced binary targets use this as the official metric.
import numpy as np
def balanced_log_loss(y_true, y_pred):
"""Compute class-balanced log loss.
Args:
y_true: binary labels (0 or 1)
y_pred: predicted probability of class 1
Returns:
Balanced log loss (lower is better)
"""
y_pred = np.clip(y_pred, 1e-15, 1 - 1e-15)
n_0 = np.sum(1 - y_true)
n_1 = np.sum(y_true)
loss_0 = -np.sum((1 - y_true) * np.log(1 - y_pred)) / n_0
loss_1 = -np.sum(y_true * np.log(y_pred)) / n_1
return (loss_0 + loss_1) / 2
# Usage
score = balanced_log_loss(y_val, model.predict_proba(X_val)[:, 1])
log_loss(y, p, sample_weight=inverse_freq) but more explicit1/N_kdata-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