Skip to content

Quick start

The example estimates the share of radiology reports that mention an incidental finding. A language model has read all 50 000 reports; a radiologist can check a few hundred.

1. Plan

From a previous validation study the model has sensitivity 0.90 and specificity 0.95, and the finding is expected in about 20 % of reports.

import fewlabels as fl

params = fl.DesignParameters.from_proportion(prevalence=0.2, sensitivity=0.9, specificity=0.95)
print(fl.required_labels(0.02, params, n_unlabeled=50_000))  # 512
print(fl.required_labels(0.02, fl.DesignParameters(params.sd_y, 0)))  # 1537 without the model

The model saves about two thirds of the radiologist's work for the same margin of error of two percentage points.

If a small pilot is available, plan from it with pessimistic values:

params = fl.DesignParameters.from_pilot(y_pilot, preds_pilot, conservative=True, seed=0)

2. Label and estimate

Select the reports for review uniformly at random, then:

result = fl.ppi_mean(y, preds_labeled, preds_unlabeled, alpha=0.05)
print(result.estimate, result.ci)
print(f"worth {result.effective_labels:.0f} labels without the model")

3. Check robustness

Were some reports skipped by the radiologist? Measure how strong a selection effect would have to be to change the conclusion:

fl.tipping_point(y, preds_labeled, preds_unlabeled, null=0.15)

A tipping point of 2 means that the conclusion holds unless the odds of being reviewed differed by a factor of two between reports with and without the finding.

4. Command line

fewlabels plan --prevalence 0.2 --sensitivity 0.9 --specificity 0.95 \
    --half-width 0.02 --unlabeled 50000