Python脚本报错:'StaticDedupe'对象无'match'属性,求排查
解决StaticDedupe对象无
match属性的错误 嘿,我来帮你搞定这个问题!先看看你的代码和遇到的错误:
你的代码片段
logger.info('Clustering.....') clustered_dupes = deduper.match(data_d, threshold=0.5) logger.info('Clustering completed') logger.info(str(len(clustered_dupes)) +' duplicate sets') clustered_dupes_list=list(clustered_dupes)
遇到的错误
File "<ipython-input-2-338d12285e67>", line 307, in <module> clustered_dupes = deduper.match(data_d, threshold=0.5) AttributeError: 'StaticDedupe' object has no attribute 'match'
问题原因&解决方案
这个问题其实是dedupe库中不同类的API差异导致的:你实例化的deduper是StaticDedupe对象,而match()方法是属于训练阶段使用的Dedupe类的,StaticDedupe确实没有这个方法。
如果是用训练好的模型进行批量去重,StaticDedupe对应的方法是partition(),它会返回两个结果:分组后的重复项集合,以及未匹配的单独记录。你只需要把代码改成这样:
logger.info('Clustering.....') # 替换match为partition,接收两个返回值 clustered_dupes, unclustered_records = deduper.partition(data_d, threshold=0.5) logger.info('Clustering completed') logger.info(f'{len(clustered_dupes)} duplicate sets') clustered_dupes_list = list(clustered_dupes)
简单来说,StaticDedupe是专门用来加载预训练模型做批量去重的,它的设计就是用partition来处理数据,而match是训练过程中用来测试匹配逻辑的方法,换个方法就搞定啦!
内容的提问来源于stack exchange,提问作者Raymondoshea
相关产品推荐
相关产品推荐

