【问题标题】:ValueError: Duplicated level name: "rec_id", assigned to level 1, is already used for level 0ValueError:重复的级别名称:“rec_id”,分配给级别 1,已用于级别 0
【发布时间】:2018-07-01 16:32:10
【问题描述】:

虽然我在record linkage python 文档中实现了这个代码示例:

import recordlinkage
from recordlinkage.datasets import load_febrl4

dfA, dfB = load_febrl4()

# Indexation step
indexer = recordlinkage.BlockIndex(on='given_name')
pairs = indexer.index(dfA, dfB)

# Comparison step
compare_cl = recordlinkage.Compare()

compare_cl.exact('given_name', 'given_name', label='given_name')
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(pairs, dfA, dfB)

# Classification step
matches = features[features.sum(axis=1) > 3]
print(len(matches))

我遇到以下错误:

Error: ValueError: Duplicated level name: "rec_id", assigned to level 1, is already used for level 0.

【问题讨论】:

  • 代码运行没有错误,并在 Jupyter 上显示所需的输出
  • @NipunSampath 对于不使用 Jupyter 笔记本的人,您是否知道可能导致该错误的原因?
  • 谢谢,它在 Jupyter notebook 上也对我有用。
  • 我认为这与版本有关。虽然不确定

标签: python record-linkage


【解决方案1】:

(在 Eclipse 或 Visual Studio 代码中)Python 记录链接 是一种算法;因此,在使用Template design pattern 时值得实施。

另外,请确保在安装virtualenv 中的要求之前升级python2

升级python2

curl https://bootstrap.pypa.io/get-pip.py | python

以后

pip install -r requirements.txt

这样,ValueError 消失了。

【讨论】:

    猜你喜欢
    • 2021-01-25
    • 2021-05-17
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多