skills/cv/slice-location-weighted-prior/SKILL.md
Encode the empirical per-position event rate as a soft prior over slice index by binning normalized slice location and looking up a precomputed weight vector — adds class-aware spatial context to a per-slice classifier without changing the model
npx skillsauth add wenmin-wu/ds-skills cv-slice-location-weighted-priorInstall 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.
In CT pathology detection, lesion likelihood is rarely uniform across the volume: pulmonary emboli concentrate in specific lung regions, brain hemorrhages cluster by anatomical landmark, kidney stones live in the lower third. A per-slice 2D CNN sees one slice at a time and has no idea where in the volume that slice sits, so it can't exploit this prior. The fix is to compute the empirical event rate per normalized slice-position bin on the training set, store it as a small lookup table, and pass each slice's binned weight as a feature (or multiply it into the predicted score post-hoc). Costs ~10 lines and consistently improves slice-level AUC by a few points.
import numpy as np
import pandas as pd
# 1. Compute the empirical prior on the training set
N_BINS = 8
df['slice_loc'] = df['series_index'] / (df['num_images'] - 1).clip(lower=1)
df['bin'] = (df['slice_loc'] * N_BINS).clip(0, N_BINS - 1).astype(int)
prior = (
df.groupby('bin')['has_event']
.mean()
.reindex(range(N_BINS), fill_value=0.0)
.values
)
# e.g. [0.0033, 0.0597, 0.3265, 0.6745, 0.7134, 0.4734, 0.0741, 0.0037]
# 2. At training/inference time, attach the prior as a per-slice feature
def attach_prior(test_df, prior, n_bins=N_BINS):
test_df['slice_loc'] = test_df['series_index'] / (test_df['num_images'] - 1).clip(lower=1)
test_df['bin'] = (test_df['slice_loc'] * n_bins).clip(0, n_bins - 1).astype(int)
test_df['loc_prior'] = test_df['bin'].map(lambda b: prior[b])
return test_df
[0, 1] within each series — series have variable lengths, so absolute index won't transfer(num_images - 1) at 1: defends against single-slice series that would divide by zero.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