Score a Match_Features table with a fitted Filter_Model and
return a Calibrated_Matches object. When matches is supplied,
the original match table is enriched with tp_prob and
predicted_tp columns and stored in the result's @matches slot;
when matches is NULL, the features table itself is enriched and
stored.
Usage
apply_filter(
features,
filter_model,
threshold = NULL,
threshold_rule = c("youden", "target_recall", "cost_weighted"),
target_recall = 0.95,
cost_ratio = 1,
matches = NULL,
...
)Arguments
- features
A
Match_Featuresobject.- filter_model
A
Filter_Modelproduced byfit_filter().- threshold
Numeric scalar in (0, 1) or
NULL. When non-NULLit is used verbatim and overridesthreshold_rule. WhenNULL, the threshold is chosen on the training labels perthreshold_rule. Decision 13.7 default.- threshold_rule
The operating-point rule used when
thresholdisNULL:"youden"(default, maximise Youden's J, symmetric error costs),"target_recall"(the highest threshold still achievingtarget_recall), or"cost_weighted"(minimisecost_ratio * FN + FP). For a firm panel the recall-favouring rules are usually the right operating point, splitting one business across years is worse than admitting a few co-located firms a later collapse can still catch.- target_recall
Target recall in (0, 1] for
threshold_rule = "target_recall". Default0.95.- cost_ratio
cost(FN) / cost(FP)forthreshold_rule = "cost_weighted";> 1favours recall. Default1(symmetric).- matches
Optional raw matches table to enrich. When supplied,
tp_prob/predicted_tpare broadcast onto every row of the pair (candidates: bothsource == "base"andsource == "target"rows of amatch_id; duplicates: every row of aduplicate_group).- ...
Reserved for future expansion.
Examples
strat <- search_strategy(
workshop ~ normalize_text() + word_tokens(min_nchar = 3),
proprietor ~ normalize_text() + word_tokens(min_nchar = 2),
block_by = c("postcode_area", "trade"),
threshold = 0.30
)
matches <- search_candidates(
workshop_listings, workshop_register,
base_id = "listing_id", target_id = "reg_no", strategy = strat
)
feats <- match_features(matches, strat,
base = workshop_listings, id = "listing_id",
target = workshop_register, target_id = "reg_no")
model <- fit_filter(feats, match_labels_example)
# Broadcast the true-positive probability back onto the match rows.
apply_filter(feats, model, matches = matches)
#>
#> ── Calibrated_Matches ──────────────────────────────────────────────────────────
#> <joinery::Calibrated_Matches>
#> threshold : 0.7237 (method: youden_j)
#> n_rows : 1930
#> predicted_tp == 1: 1232
#> predicted_tp == 0: 698
#> tp_prob quantiles: 0.000 / 0.016 / 0.972 / 0.998 / 1.000
