Confidence probability clipping

From wenmin-wu/ds-skills · View interactive version

Confidence probability clipping is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Hard-clips predicted probabilities to 0 or 1 when they exceed high-confidence thresholds, reducing log loss on near-certain predictions.

How to use this skill

Skill file

Confidence Probability Clipping

Overview

Log loss penalizes confident wrong predictions exponentially — predicting 0.99 when the true label is 0 costs 100x more than predicting 0.5. But for predictions the model is very confident about, the risk of being wrong is low. Clipping probabilities above/below asymmetric thresholds (e.g., >0.86→1.0, <0.14→0.0) converts these near-certain soft predictions to hard ones. When correct, this eliminates residual log loss from the epsilon gap; when wrong, the loss is bounded by the threshold. On balanced log loss metrics, this typically improves score by 0.001-0.01.

Quick Start

import numpy as np

def clip_confident_predictions(probs, upper=0.86, lower=0.14):
    """Hard-clip probabilities at confidence thresholds.

    Args:
        probs: predicted P(class_0), shape (n,)
        upper: threshold above which to clip to 1.0
        lower: threshold below which to clip to 0.0
    Returns:
        Clipped probabilities
    """
    clipped = probs.copy()
    clipped[clipped > upper] = 1.0
    clipped[clipped < lower] = 0.0
    return clipped

p0 = model.predict_proba(X_test)[:, 0]
p0 = clip_confident_predictions(p0, upper=0.86, lower=0.14)
submission['class_0'] = p0
submission['class_1'] = 1 - p0

Workflow

  1. Get predicted probabilities from model/ensemble
  2. Set upper and lower confidence thresholds
  3. Clip probabilities beyond thresholds to 0 or 1
  4. Ensure complementary probabilities sum to 1

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.