Skip to content
Back to skills

Unknown Class Residual Probability

ASecurity

Estimate out-of-distribution class probability as the product of (1 - p_i) across all known classes, scaled by a calibrated prior

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
testingpython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill unknown-class-residual-probability --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Unknown Class Residual Probability?

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

Security grade badge for Unknown Class Residual Probability
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-unknown-class-residual-probability/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-unknown-class-residual-probability)

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: timeseries-unknown-class-residual-probability
description: Estimate out-of-distribution class probability as the product of (1 - p_i) across all known classes, scaled by a calibrated prior
domain: timeseries
---

# Unknown Class Residual Probability

## Overview

When test data may contain an unseen class not present in training (open-set classification), estimate its probability using the "residual" approach: multiply (1 - p_i) across all known classes. If the model is confident in no known class, the product is high — indicating a likely OOD sample. Scale by a prior reflecting the expected OOD fraction, then normalize by the mean to calibrate.

## Quick Start

```python
import numpy as np

def add_unknown_class_prob(preds, prior=0.14):
    """Add an unknown-class probability column to predictions.
    
    Args:
        preds: (n_samples, n_classes) array of known-class probabilities
        prior: expected fraction of OOD samples (tune on validation)
    Returns:
        (n_samples, n_classes+1) array with unknown class appended
    """
    # Product of complements — high when no known class is confident
    ood_score = np.ones(preds.shape[0])
    for i in range(preds.shape[1]):
        ood_score *= (1 - preds[:, i])
    
    # Scale by prior and normalize
    ood_prob = prior * ood_score / np.mean(ood_score)
    
    # Append and renormalize
    full_preds = np.column_stack([preds, ood_prob])
    full_preds /= full_preds.sum(axis=1, keepdims=True)
    return full_preds
```

## Key Decisions

- **prior=0.14**: fraction of OOD samples expected; tune on leaderboard or validation
- **Product not max**: product captures "confident in nothing"; max(1-p) misses partial confidence
- **Normalize by mean**: prevents the OOD column from dominating or vanishing
- **Renormalize rows**: ensures probabilities sum to 1 after adding the new column

## References

- Source: [simple-neural-net-for-time-series-classification](https://www.kaggle.com/code/meaninglesslives/simple-neural-net-for-time-series-classification)
- Competition: PLAsTiCC Astronomical Classification

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.