wenmin-wu/ds-skills/balanced-log-loss

Claude Code and agent skill by wenmin-wu/ds-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Class-balanced log loss that weights each class by the inverse of its sample count, equalizing the contribution of minority and majority classes.

Install

npx vskill@latest install wenmin-wu/ds-skills/balanced-log-loss

SKILL.md

The same SKILL.md was published earlier as majiayu000/claude-skill-registry-data/balanced-log-loss.

Balanced Log Loss

Overview

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.

Quick Start

python
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])

Workflow

  1. Clip predictions to avoid log(0)
  2. Compute log loss for each class separately
  3. Divide each class's loss by its sample count
  4. Average the two normalized losses

Key Decisions

  • Clipping: 1e-15 is standard; prevents -inf from log(0)
  • vs sample_weight: Equivalent to log_loss(y, p, sample_weight=inverse_freq) but more explicit
  • Multiclass: Extend by weighting each of K classes by 1/N_k
  • Optimization: Train with class-weighted BCE to optimize for this metric directly

References

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/wenmin-wu/ds-skills/balanced-log-loss/badge)](https://verified-skill.com/skills/wenmin-wu/ds-skills/balanced-log-loss)

Something wrong with this skill or its page? Tell us.