Selective prediction
neureptrace.decoding.selective_prediction converts probability traces into predictions plus an abstention mask.
Fixed confidence, entropy, and margin thresholds are ordinary post-hoc prediction rules. A requested target coverage sets the confidence threshold from the unlabeled probability batch and should be reported as an unlabeled target-adaptive thresholding step.
The public API intentionally has no label-vector argument.
Typical usage:
from neureptrace.decoding.selective_prediction import selective_predict
result = selective_predict(
probabilities,
classes=classes,
confidence_threshold=0.75,
)
predictions = result.predictions
selected = result.selected_mask
neureptrace.decoding.selective_prediction
Selective prediction utilities for probability traces.
The helpers in this module turn classifier probability rows into predictions plus an abstention mask. Fixed thresholds are ordinary post-hoc prediction rules. A coverage-calibrated threshold uses the unlabeled target probability distribution itself and is therefore marked as an unlabeled target-adaptive Category-2 step.
No label vector is accepted by the public prediction API.
SelectivePredictionResult
dataclass
Predictions, retained-row mask, and uncertainty diagnostics.
Source code in src/neureptrace/decoding/selective_prediction.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
coverage
property
Fraction of rows retained for prediction.
selective_predict(probabilities, *, classes=None, confidence_threshold=None, max_entropy=None, min_margin=None, target_coverage=None, epsilon=DEFAULT_EPSILON)
Predict with optional abstention from probability rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probabilities
|
Sequence[Sequence[float]] | ndarray
|
Row-wise class probabilities or non-negative scores. Rows are normalized defensively before metrics are computed. |
required |
classes
|
Sequence[Any] | ndarray | None
|
Optional class labels for prediction output. If omitted, dense integer class ids are used. |
None
|
confidence_threshold
|
float | str | None
|
Fixed minimum top-class probability required for selection. |
None
|
max_entropy
|
float | str | None
|
Fixed maximum entropy allowed for selection. |
None
|
min_margin
|
float | str | None
|
Fixed minimum gap between the largest and second-largest probability. |
None
|
target_coverage
|
float | str | None
|
Optional desired retained fraction in |
None
|
epsilon
|
float | str
|
Numerical floor for row normalization and entropy. |
DEFAULT_EPSILON
|
Returns:
| Type | Description |
|---|---|
SelectivePredictionResult
|
Predicted labels, selection mask, and uncertainty metrics. |
Source code in src/neureptrace/decoding/selective_prediction.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
normalize_probability_rows(probabilities, *, epsilon=DEFAULT_EPSILON)
Return finite row-normalized probabilities.
Source code in src/neureptrace/decoding/selective_prediction.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
probability_entropy(probabilities, *, epsilon=DEFAULT_EPSILON)
Return row-wise Shannon entropy.
Source code in src/neureptrace/decoding/selective_prediction.py
150 151 152 153 154 155 | |
probability_margin(probabilities)
Return top-one minus top-two probability margin per row.
Source code in src/neureptrace/decoding/selective_prediction.py
158 159 160 161 162 163 | |
confidence_threshold_for_coverage(confidence, *, target_coverage)
Return the smallest confidence among the top-coverage rows.
Source code in src/neureptrace/decoding/selective_prediction.py
166 167 168 169 170 171 172 173 174 175 176 177 | |