denselinkage.metrics.tune_threshold

denselinkage.metrics.tune_threshold(candidates: Sequence[CandidatePair], *, gold: LabeledPairs, thresholds: Sequence[float] | None = None, directed: bool = True) ThresholdSweep[source]

Sweep a similarity threshold over scored candidates and return the full precision/recall/F1 curve as a ThresholdSweep.

Each candidate is classified a match iff similarity_score >= t (inclusive, matching ThresholdMatcher). A candidate with similarity_score is None is undecidable and counts as an error at every threshold — excluded from false negatives and surfaced as n_errors — the same accounting linkage_metrics uses. directed follows linkage_metrics (pass directed=False for dedupe candidates).

thresholds defaults to the sorted distinct candidate scores — the only cut points that change the prediction, so the curve is exact and ThresholdSweep.best_f1 finds the true optimum; pass an explicit grid to override. An empty candidate set (or empty grid) yields an empty sweep.