skills/timeseries/unknown-class-residual-probability/SKILL.md
Estimate out-of-distribution class probability as the product of (1 - p_i) across all known classes, scaled by a calibrated prior
npx skillsauth add wenmin-wu/ds-skills timeseries-unknown-class-residual-probabilityInstall 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.
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.
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
data-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