A Review Queue Instead of a Score: Anomaly Detection at a Fixed Reviewer Budget¶
A reviewer can inspect 100 records. The model can score a million. The mismatch determines which metric matters.
In this real-data example, an Extended Isolation Tree places 16 hazardous shifts among the first 100 reviews, out of 42 hazards in 646 held-out shifts. Random selection would find about 6.5 hazards on average. That is a useful concentration of cases, but it also leaves 26 hazards outside the queue. Both facts belong in the decision.
The dataset concerns mining safety, not payment fraud. It lets us demonstrate a review-capacity workflow on observed labels. Applying that workflow to fraud requires fraud-specific data, costs, delayed outcomes, and operational checks. We do not infer fraud performance from geophysical measurements.
1. Define the queue before choosing the detector¶
An anomaly score orders observations by the detector's notion of unusualness. It does not automatically estimate the probability of harm. A rare but legitimate transaction can score highly. A common harmful pattern can blend into the majority.
The queue adds a decision: review the top \(k\) records. Here, \(k\) is the number of cases a team can handle during the evaluation window. A contamination parameter can calibrate an anomaly cutoff, but that cutoff does not guarantee exactly \(k\) cases, especially when scores tie. Review capacity and contamination are different controls.
flowchart LR
A["New records with stable IDs"] --> B["Score using a fitted detector"]
B --> C["Sort descending; break ties deterministically"]
D["Reviewer capacity k"] --> E["Select first k cases"]
C --> E
E --> F["Inspect evidence and record outcome"]
F --> G["Evaluate yield, missed cases, and review burden"]
The operational output is the selected list, not a score histogram. A useful list identifies the source record, its rank, score, and evidence available to the reviewer. It also records the model version and scoring time so that a decision can be reconstructed later.
Next: connect the queue to a real outcome and keep that outcome out of fitting.
2. Use observed shifts and a separate test cohort¶
The UCI seismic-bumps source describes a mining hazard problem. Its measurements summarize earlier shift activity, while the class concerns a high-energy bump in the next shift. We use the processed OpenML dataset 46956 through the package's registered seismic-bumps loader.
The full table contains 2,584 shifts, including 170 hazards (6.58%). Eleven numeric predictors provide a common input surface for the three detectors. They include energy, pulse counts, and counts of earlier bumps. Categorical hazard assessments and shift type are excluded for this controlled numeric comparison; that is a modeling choice, not evidence that those fields lack value.
A stratified 75%/25% split with seed 42 produces 1,938 training shifts and 646 test shifts. The test cohort contains 42 hazards, or 6.50%. Labels determine the split balance and evaluate the result, but they are not supplied as detector inputs.
flowchart TD
A["2,584 labelled historical shifts"] --> B["Fixed stratified split"]
B --> C["1,938 training shifts"]
B --> D["646 test shifts; 42 hazards"]
C --> E["Fit detector using numeric features only"]
E --> F["Freeze model"]
F --> G["Score test features"]
G --> H["Top-k held-out queue"]
D --> I["Use labels only to evaluate yield"]
H --> I
This replaces the earlier in-sample comparison. Scoring training rows can describe the fitted cohort, but it is weaker evidence about new records. A random held-out split still does not establish performance on later shifts at another mine. The benchmark does not give us enough operational chronology to claim a prospective backtest.
Next: make precision and recall concrete enough to connect them to a team's workload.
3. Read precision, recall, and lift at the same budget¶
For a queue containing \(k\) records:
Precision answers how often a review finds a labeled hazard. Recall answers how many hazards the queue captures. Lift divides queue precision by the test cohort's prevalence. None of these quantities says whether reviewing a shift prevents an incident.
At 100 reviews, EIF finds 16 hazards. Its precision is 16% and its recall is 38.10%. The other 84 reviews concern shifts without the hazard label. The unreviewed group still contains 26 hazards. A team deciding whether that workload is acceptable needs both denominators.
| EIF queue at 100 reviews | Hazard label | No hazard label |
|---|---|---|
| Selected for review | 16 | 84 |
| Outside the queue | 26 | 520 |
The random baseline is an expectation under uniform selection without replacement, not a separately fitted model. Its expected precision is \(42/646\), or 6.50%. Its expected recall at 100 reviews is \(100/646\), or 15.48%. The EIF queue has 2.46 times the expected random precision in this split.
Next: compare detectors at the capacity you actually plan to use.
4. Fit once, score held-out rows, then compare budgets¶
The runnable example below uses the registered dataset and keeps the target outside the model's feature matrix. A positive anomaly score is not interpreted as a calibrated hazard probability. We compare only the descending ranking.
from mltreelib import AnomalyModel, load_dataset
from mltreelib.data import Dataset
raw = load_dataset("seismic-bumps")
target = "HighEnergySeismicBump"
columns = {name: values for name, values in raw["columns"].items()
if name != target and raw["dtypes"][name] == "numeric"}
columns[target] = [int(value == "Yes") for value in raw["columns"][target]]
ds = Dataset(columns, target=target, name="seismic_bumps")
train, test = ds.split(test_size=0.25, stratify=True, seed=42)
print(f"Train={train.n_rows}; test={test.n_rows}; hazards={sum(test.y)}")
for kind in ("eif", "det", "rct"):
detector = AnomalyModel(kind=kind, max_depth=8, min_rows=20,
contamination=0.07, seed=42).fit(train)
scores = detector.score_samples(test)
order = sorted(range(len(scores)), key=lambda i: (-scores[i], i))
found = sum(test.y[i] for i in order[:100])
print(f"{kind}: hazards@100={found}; precision={found / 100:.2%}; recall={found / sum(test.y):.2%}")
Train=1938; test=646; hazards=42
eif: hazards@100=16; precision=16.00%; recall=38.10%
det: hazards@100=6; precision=6.00%; recall=14.29%
rct: hazards@100=7; precision=7.00%; recall=16.67%
The output counts are easier to audit than a rounded lift alone. Detector parameters are fixed, not chosen by inspecting this test cohort. The 100-case budget is specified as the focal illustration; the wider budget curve describes tradeoffs, rather than a search for the best-looking cutoff.
The complete script regenerates the plot and prints results at 25, 50, 100, 150, 200, and 300 reviews:
Next: use the full curve to see where a detector helps and where the ranking changes.
5. The winner depends on capacity¶
| Detector | Precision@25 | Precision@50 | Precision@100 | Lift@100 | Recall@200 |
|---|---|---|---|---|---|
Extended Isolation Tree (eif) |
20.00% | 16.00% | 16.00% | 2.46x | 50.00% |
Density Estimation Tree (det) |
0.00% | 4.00% | 6.00% | 0.92x | 38.10% |
Random Cut Tree (rct) |
16.00% | 8.00% | 7.00% | 1.08x | 47.62% |
| Uniform random expectation | 6.50% | 6.50% | 6.50% | 1.00x | 30.96% |
The left panel answers a workload question: what fraction of reviewed cases carry the hazard label? The right panel answers a coverage question: what fraction of all hazards does that workload find? Increasing capacity can improve recall while lowering precision because the queue reaches less concentrated regions of the ranking.
EIF is strongest at the focal 100-case budget. DET's first 25 reviews find no labeled hazards, so statistical rarity from that fitted engine is not a useful hazard screen at that operating point. RCT changes position as the budget grows: at 300 reviews it finds 32 of 42 hazards, versus 22 for EIF. A single global “best detector” label would hide that reversal.
These are one-split observations with only 42 test hazards. One additional hazard changes Precision@25 by four percentage points. We do not report confidence intervals or a significance claim because this run does not supply repeated evaluation evidence. Before choosing an engine, use a validation cohort, then check the chosen engine and budget on a separate final test.
Next: make the selected cases inspectable without overstating what the explanation means.
6. Give reviewers evidence, not a causal story¶
AnomalyModel.summary() includes a training-case review view for supported engines. It does not automatically become the held-out queue scored above. That distinction matters when a notebook prints a fitted summary immediately after evaluating new records.
For numeric fields, the current leading-feature list ranks standardized deviations from the training distribution. It tells a reviewer which measurements are far from their marginal averages. It does not show each feature's contribution to the detector score, prove a cause of the hazard, or reliably explain categorical anomalies. An unusual combination can matter even when no single measurement is extreme.
A production handoff therefore needs a richer record:
| Queue field | What it gives the reviewer |
|---|---|
| Stable source ID and scoring time | A record to locate and an information cutoff |
| Rank, score, and selection rule | Why this case entered today's queue |
| Observed values and missing fields | Evidence available for inspection |
| Standardized deviations, clearly labeled | A starting point for examination, not attribution |
| Reviewer outcome and eventual label | Evidence for measuring yield and improving the process |
Keep source IDs alongside feature rows; the local row index used to break ties in this example is not an operational identifier. If a saved model is used, check score, schema, threshold, and report behavior after loading. The Spec 35 persistence audit identifies gaps that must close before promising a complete saved review workflow.
7. Turn review outcomes into the next evaluation¶
A queue is useful only if people can act on it. Record investigation outcomes and review time, and distinguish a model false alarm from a case whose true outcome remains unknown. In fraud work, chargebacks or investigations can arrive long after scoring. A reviewed-only label set can also bias the next model toward yesterday's selection policy.
flowchart LR
A["Locked detector and review budget"] --> B["Score new cohort"]
B --> C["Reviewer records evidence and disposition"]
C --> D["Wait for outcome maturity"]
D --> E["Measure yield and missed-event coverage"]
E --> F["Validate the next version on separate data"]
F --> A
The anomaly guide explains engine choices and scoring interfaces. The anomaly-tree concept page explains how isolation and density models differ. Use those details after deciding the action and evaluation boundary; an elegant detector cannot compensate for an undefined review process.
The next real-world experiment should lock the budget, preserve event timing, and evaluate later records. Ask how many extra useful cases each additional block of reviews buys, what remains outside the queue, and how those misses compare with the cost of investigation. A better score matters when it changes that decision.