skills/cv/ordinal-multilabel-encoding/SKILL.md
Encodes ordinal classes as cumulative binary labels (class N activates labels 0..N), enabling sigmoid + BCE training for ordinal regression.
npx skillsauth add wenmin-wu/ds-skills cv-ordinal-multilabel-encodingInstall 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.
Standard classification treats ordinal classes (severity grades 0-4) as unrelated categories, ignoring their natural order. Ordinal multilabel encoding converts class K into K+1 binary labels where all labels up to K are activated. For example, class 3 becomes [1,1,1,1,0]. Training with sigmoid + BCE per label teaches the model that higher classes imply all lower classes. Decoding is simply summing active labels minus one.
import numpy as np
def ordinal_encode(labels, n_classes=5):
"""Convert ordinal labels to cumulative binary encoding.
Args:
labels: (N,) integer labels in [0, n_classes-1]
n_classes: number of ordinal classes
Returns:
(N, n_classes) binary array
"""
encoded = np.zeros((len(labels), n_classes), dtype=np.float32)
for i, label in enumerate(labels):
encoded[i, :label + 1] = 1.0
return encoded
def ordinal_decode(preds, threshold=0.5):
"""Decode sigmoid predictions back to ordinal labels."""
return (preds > threshold).astype(int).sum(axis=1) - 1
# Training
y_encoded = ordinal_encode(y_train, n_classes=5)
model.compile(loss='binary_crossentropy', optimizer='adam') # sigmoid output
model.fit(X_train, y_encoded)
# Inference
y_pred = ordinal_decode(model.predict(X_test))
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