我正在使用重复数据消除库将个人记录彼此匹配。我的资料包括姓名、出生日期、地址、电话号码和其他个人识别信息。
我的问题是:如果两条记录有一个匹配的姓名和电话号码(例如),我总是希望100%有把握地匹配它们。
下面是我的一些代码的示例:

fields = [
    {'field' : 'LAST_NM', 'variable name' : 'last_nm', 'type': 'String'},
    {'field' : 'FRST_NM', 'variable name' : 'frst_nm', 'type': 'String'},
    {'field' : 'FULL_NM', 'variable name' : 'full_nm', 'type': 'Name'},
    {'field' : 'BRTH_DT', 'variable name' : 'brth_dt', 'type': 'String'},
    {'field' : 'SEX_CD', 'type': 'Exact'},
    {'field' : 'FULL_US_ADDRESS', 'variable name' : 'us_address', 'type': 'Address'},
    {'field' : 'APT_NUM', 'type': 'Exact'},
    {'field' : 'CITY', 'type': 'ShortString'},
    {'field' : 'STATE', 'type': 'ShortString'},
    {'field' : 'ZIP_CD', 'type': 'ShortString'},
    {'field' : 'HOME_PHONE', 'variable name' : 'home_phone', 'type': 'Exact'},
    {'type': 'Interaction', 'interaction variables' : ['full_nm', 'home_phone']},

在重复数据消除库中,是否可以显式匹配两个或多个字段?根据文档,“交互字段乘以多个变量的值。”(https://dedupe.readthedocs.org/en/latest/Variable-definition.html#interaction)。我想实现一个严格的规则,它匹配100%的信心-不仅仅是乘以变量的值。我问的原因是,我发现重复数据消除偶尔会错过这两个条件下的一些匹配(可能是因为我没有足够长的训练时间,但不管怎样,我只是想硬编码到我的脚本这些匹配)。
有什么建议吗?

最佳答案

重复数据消除没有此功能,而且可能永远不会(我是主要作者之一)。如果确实有一条规则规定这些字段上的完全匹配意味着记录是共同引用的,则可以编写一些代码来显式匹配这些字段,然后再将其余记录发送到重复数据消除中。

exact_matches = defaultdict(list)
for record_id, record in records.items():
    match_key = (record['name'], record['phone'])
    exact_matches[match_key].append(record_id)

partially_deduplicated = []
exact_lookup = {}
for match_group in exact_matches.values():
     head_id = match_group.pop()
     partially_deduplicated.append((head_id, records[head_id]))
     for dupe_id in match_group :
         exact_lookup[dupe_id] = head_id

关于python - 使用Python Dedupe库设置用于匹配记录的显式规则,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32550441/

10-11 20:31
查看更多