python - 在 python 中使用 ECM 记录链接

标签 python ecm record-linkage

我正在处理记录链接问题并应用无监督算法,因为我没有外部标签。

我应用了 ECM 算法。使用的代码是:

import recordlinkage

indexer = recordlinkage.BlockIndex(on=['FirstName_CD','LastName_CD'])
pairs = indexer.index(data1, data2)

compare_cl = recordlinkage.Compare()

compare_cl.string('FirstName_CD', 'FirstName_CD', method='jarowinkler', threshold=0.50,label='given_name')
compare_cl.string('LastName_CD', 'LastName_CD', method='jarowinkler', threshold=0.50, label='surname')
compare_cl.exact('Date.Of.Birth_CD', 'Date.Of.Birth_CD', label='date_of_birth')
compare_cl.exact('Gender_CD', 'Gender_CD', label='gender')
compare_cl.exact('Profession_CD', 'Profession_CD', label='profession')
compare_cl.string('Address_CD', 'Address_CD', threshold=0.85, label='address_1')

features = compare_cl.compute(pairs,data1)

ecm = recordlinkage.ECMClassifier()
result_ecm=ecm.learn(features)

现在它返回一个多索引。我的问题是我可以从中得出什么推论?如何获取匹配/不匹配信息?

最佳答案

ecm.learn() 返回的 MultiIndex 基本上是一组索引对,它们是分类器对哪些项目匹配的猜测。 (请注意,ecm.learn() 已弃用。新函数名称为 ecm.fit_predict()。)

我不知道你的数据是什么样的,但这里有一个样本数据集的例子:

from recordlinkage.datasets import load_febrl4

dfA, dfB = load_febrl4()

# Indexation step
indexer = recordlinkage.Index()
indexer.block('given_name')
candidate_links = indexer.index(dfA, dfB)

# Comparison step
compare_cl = recordlinkage.Compare()
compare_cl.string('surname', 'surname', method='jarowinkler', threshold=0.85, label='surname')
compare_cl.exact('date_of_birth', 'date_of_birth', label='date_of_birth')
compare_cl.exact('suburb', 'suburb', label='suburb')
compare_cl.exact('state', 'state', label='state')
compare_cl.string('address_1', 'address_1', threshold=0.85, label='address_1')

features = compare_cl.compute(candidate_links, dfA, dfB)

ecm = recordlinkage.ECMClassifier()
matches = ecm.fit_predict(features)

(请注意,此示例基于 here 文档中的示例。)

matches 对象确实是一个 Pandas MultiIndex。我们可以将它转换为元组列表,以便更好地了解它包含的信息。

# Look at the first 5 matches
list(matches)[:5]
[('rec-2371-org', 'rec-2371-dup-0'),
 ('rec-3024-org', 'rec-3024-dup-0'),
 ('rec-4652-org', 'rec-4652-dup-0'),
 ('rec-4795-org', 'rec-4795-dup-0'),
 ('rec-1016-org', 'rec-1016-dup-0')]

这些是 dfAdfB 数据框中的索引名称。我们可以查找它们以了解它们实际上是匹配的:

dfA.loc['rec-2371-org'], dfB.loc['rec-2371-dup-0']
 given_name           michaela
 surname              dunstone
 street_number              37
 address_1        deane street
 address_2            rosedown
 suburb              woodcroft
 postcode                 2065
 state                     vic
 date_of_birth        19121018
 soc_sec_id            3166178
 Name: rec-2371-org, dtype: object

 given_name           michaela
 surname              dunstone
 street_number              37
 address_1        deane street
 address_2            rosedlwn
 suburb              woodcroft
 postcode                 2065
 state                     vic
 date_of_birth        19121018
 soc_sec_id            3166178
 Name: rec-2371-dup-0, dtype: object

关于python - 在 python 中使用 ECM 记录链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50508739/

相关文章:

aem - AEM 中的内容文件夹和结构文件夹有什么区别

algorithm - 结构化数据的模糊匹配

java - 使用 Java 上的评分框架/应用程序/服务器进行重复数据删除,以与数据库输入分段配合使用

python - 将python路径放在windows机器上

python - 在 Mac OS/X 1.8.5 中为 Python 2.7 安装 Twisted

python - 根据条件从 DataFrame 中删除值

python - 在Python中使用Ray并行化任务,得到 "Aborted (core dumped)"

javascript - Alfresco Action - 使用 Action 将文件转换为 PDF

java - CMIS 浏览器网络应用程序