Skip to content
Back to skills

Confidence Threshold Multilabel

ASecurity

Assigns multiple labels per sample using a confidence threshold on sigmoid outputs with a fallback negative class.

  • 61 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 12, 2026
toolspython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill confidence-threshold-multilabel --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Confidence Threshold Multilabel?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Confidence Threshold Multilabel
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-confidence-threshold-multilabel/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-confidence-threshold-multilabel)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cv-confidence-threshold-multilabel
description: >
  Assigns multiple labels per sample using a confidence threshold on sigmoid outputs with a fallback negative class.
---
# Confidence Threshold Multi-Label Assignment

## Overview

For multi-label classification, apply a confidence threshold to sigmoid outputs to assign zero or more labels per sample. Samples with no label above the threshold receive a fallback "Negative" class with confidence `1 - max_pred`. Produces both label assignments and confidence scores per prediction.

## Quick Start

```python
import numpy as np

def multilabel_assign(probs, threshold=0.5, negative_class_id=18):
    """Assign labels from sigmoid probabilities with fallback.

    Args:
        probs: array of shape (n_classes,) with sigmoid outputs
        threshold: confidence cutoff for positive assignment
        negative_class_id: class ID for the fallback negative label

    Returns:
        list of (label_id, confidence) tuples
    """
    assignments = []
    for cls_id, p in enumerate(probs):
        if p >= threshold:
            assignments.append((cls_id, float(p)))

    if not assignments:
        assignments.append((negative_class_id, float(1.0 - probs.max())))

    return assignments


def format_submission(cell_id, assignments, mask_rle):
    """Format as competition submission string."""
    parts = []
    for label_id, conf in assignments:
        parts.append(f"{label_id} {conf:.4f} {mask_rle}")
    return " ".join(parts)
```

## Workflow

1. Run model inference to get per-class sigmoid probabilities
2. Apply threshold to select positive labels
3. If no labels pass threshold, assign negative/background class
4. Attach confidence scores for downstream calibration
5. Format predictions with associated masks/regions

## Key Decisions

- **Threshold tuning**: Optimize on validation set per-class or globally; 0.5 is a starting point
- **Per-class thresholds**: Rare classes may need lower thresholds to improve recall
- **Negative fallback**: `1 - max_pred` gives meaningful confidence for negative predictions
- **Calibration**: Sigmoid outputs are not calibrated; consider Platt scaling if scores matter

## References

- HPA Single Cell Classification competition (Kaggle)
- Source: [hpa-cellwise-classification-inference](https://www.kaggle.com/code/dschettler8845/hpa-cellwise-classification-inference)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.