Fast Probabilistic Record Linkage for the Julia Language
The purpose of FastLink.jl is to bring a fast record linkage package to the julia language. When attempting to match large datasets using existing libraries in R and Python, I found they can be very slow and succumb to issues with memory pressure. This implementation of the fastlink algorithm is intended to scale effeciently in parallel and be able to easily handle matches between tabular data that span millions of rows.
The basic arguments for the fastLink
function to run are
-
dfA
: ADataFrame
table of records to be matched. -
dfB
: ADataFrame
table of records to be matched. -
config
: ADict{String, Any}
that specifies how the two dataframes ought to be matched.
The match configuration for a FastLink match needs to contain certain in the base dictionary (nested dictionaries will be discussed later).
The Base Dictionary needs to contain:
-
link_type
: Eitherlink_only
,dedupe_only
, orlink_and_dedupe
. -
idvar
: AVector{String}
of length 2 that specifies the ids of the two dataframes (in[dfA, dfB]
order). -
comparisons
: aDict{String, Any}
a that defines the type of matching to be done and the variables that will be matched.
The comparison dictionary defined above can be located in the base Dictionary or can be substituted instead of a varname
dictionary in the variables
vector. The effect of nesting the comparisons in the variables
vector will lead it to be matched first using the fastlink algorithm and then treated as a single variables in the parent comparisons
dictionary. You can substitute multiple varnames
for comparisons at the same level of nestedness.
Each comparisons
dictionary much have:
-
name
: should be "total" in the base dictionary and then can be anyname
for the nested dictionaries. -
variables
: aVector{Dict{String, Any}}
that contains the individual variable dictionaries and/or acomparisons
dictionaries.
The optional parameters for the comparisons
dictionary are:
-
w_lambda::Float64
: Default 0.0. -
prior_lambda::Float64
: Default 0.0. -
threshold_match
: Lower bound for the posterior probability that will act as a cutoff for matches. Default[0.85]
. -
tol_em
: Convergence tolerance for the EM Algorithm. (default1e-05
) -
prior_pi::Float64
: Default 0.0. -
w_pi::Float64
: Default 0.0.
Individual variables can be declared in a dictionary and must contain both a varname
and method
.
-
varname
: name of the variable indfA
anddfB
to be compared. -
method
: the method to match the variable. The current accepted methods are (exact
,fuzzy
,string
,numeric
,float
,int
any of thedistmethod
options).
Each method
has a number of arguments that can be specified for that matching method.
-
term_freq_adjustment
: ABool
that determines whether you want the term frequencies for each comparision for a given variable. Note: does not adjust match weight. -
tf_adjustment_weight
: how much to weight on the term_freq_adjustment vs the predicted match value. -
tf_minimum_u_value
: minimum term frequency value to adjust by. -
partial
: ABool
that specifies whether you want to do 2 (true) or 1 (false) comparison levels for a given variable. Default valuetrue
. -
upper_case
: ABool
that specifies whether a strings column value is upper or lower (only ifmethod
=true
. Default value istrue
. -
stringdist_method
: AString
that specifies the desired string distance method ("jw" Jaro-Winkler (Default), "dl" Damerau-Levenshtein, "jaro" Jaro, "lv" Levenshtein, and "ham" Hamming). Default"jw"
. -
cut_a
: AFloat
that specifies the first lower bound for string distance cutoff for each comparison. Default0.92
. -
cut_b
: AFloat
that specifies the second lower bound for string distance (if varnames in partial) for each comparison. Default0.88
. -
w
: AFloat
that specifies the Winkler weight for jw string distance for each comparison. Default0.1
.
{
"link_type": "link_only",
"idvar": ["id", "id2"],
"comparisons": {
"name": "total",
"prior_lambda": 0.000001,
"w_lambda": 0.5,
"threshold_match": 0.88,
"variables": [
{"varname": "firstname", "method": "fuzzy", "partial": true, "cut_a": 0.92, "cut_b": 0.88, "upper": true, "tf_adjust": true, "w": 0.1},
{"varname": "middlename", "method": "exact"},
{"varname": "lastname", "method": "jarowinkler", "tf_adjust": true},
{"varname": "birthyear", "method": "exact"},
{
"comparisons": {
"name": "address",
"threshold_match": 0.92,
"variables": [
{"varname": "housenum", "method": "exact", "tf_adjust": true},
{"varname": "streetname", "method": "jarowinkler", "w": 0.1, "tf_adjust": true, "tf_adjustment_weight":0.25, "tf_minimum_u_value": 0.001},
{"varname": "city", "method": "jarowinkler", "tf_adjustment_weight":0.15, "tf_adjust": true}
]
}
}
]
}
}
For ease of extracting matches, the getMatches
function was added. You can call it on the fastLink output as the single argument getMatches(FastLinkOutput)
or with a specified threshold getMatches(FastLinkOutput, threshold_match)
.
The FastLink output is:
A Dict{String,Any}
with these vars:
ids
: A vector of vectors of tuple pairs of ids for each match pattern.idvar
: ID variable from configurationresultsEM
: The results of the Expectation Maximization algorithm
If term frequency is specified then
resultsTF
: term frequencies for each variable with specified term frequency by pattern if relevant for the pattern (if no term frequency is applied then tf_adjusted is false).
If benchmark is specified:
benchtimes
: times for each variable to be matched.
Within resultsEM
in the EM output, there is:
-
iter_converge
- number of iterations for expectation maximization algorithm to converge. -
obs_a
- observations indfA
-
obs_b
- observations indfB
-
p_m
- posterior match probability -
p_u
- posterior not match probability -
number_of_unique_patterns
- equivalent to number of rows inpatterns_w
-
number_of_comparisons
- For conveniencenrow(dfA) * nrow(dfB)
-
patterns_w
- aDataFrame
of:gamma_*
- AnInt64
with the gamma values for each variable (similar topatterns_b
)counts
- AnInt64
with counts for each agreement patternweights
- AnInt64
with partial match weights for each agreement patternp_gamma_jm
- AFloat64
that has the posterior probability that a pair matches for each agreement patternp_gamma_ju
- AFloat64
that has the posterior probability that a pair does not match for each agreement patternis_match
- ABool
that specifies whether the given pattern is above the input parameterthreshold_match
-
patterns_b
- vector of all patterns observed. each pattern as a scored number for each variable (0 nonmatch, 1 partial, 2 exact, 3 missing) -
pgamma_km
- AVector{Vector{Float64}}
with posterior probababilities for each variable in the EM algorithm. Ordered (0,1,2). -
pgamma_ku
- AVector{Vector{Float64}}
with posterior probababilities for each variable in the EM algorithm. Ordered (2,1,0). -
p_gamma_jm
- AFloat64
that has the posterior probability that a pair matches for each agreement pattern (seepatterns_w
). -
p_gamma_ju
- AFloat64
that has the posterior probability that a pair does not match for each agreement pattern (seepatterns_w
). -
varnames
- AVector{String}
of the input variable names