为 fuzzywuzzy process.extractOne 设置阈值
我目前正在两个不同的零售商之间进行一些字符串产品相似性匹配,我正在使用 fuzzywuzzy process.extractOne
function 来找到最好的匹配。
但是,我希望能够设置一个评分阈值,以便仅当分数高于某个阈值时产品才会匹配,因为目前它只是根据最接近的字符串匹配每个产品。
以下代码为我提供了最佳匹配:(当前出现错误)
title,index,score = process.extractOne(text,choices_dict)
然后我尝试使用以下代码来尝试设置阈值:
title,index,score = process.extractOne(text,choices_dict,score_cutoff=80)
这会导致以下TypeError:
TypeError:cannot unpack non-iterable NoneType object
最后,我也尝试了这以下代码:
title,index,scorer,score = process.extractOne(text,choices_dict,scorer = fuzz.token_sort_ratio,score_cutoff = 80)
这会导致以下错误:
ValueError:不够要解压的值(预期为 4,实际为 3)
I'm currently doing some string product similarity matches between two different retailers and I'm using the fuzzywuzzy process.extractOne
function to find the best match.
However, I want to be able to set a scoring threshold so that the product will only match if the score is above a certain threshold, because currently it is just matching every single product based on the closest string.
The following code gives me the best match: (currently getting errors)
title, index, score = process.extractOne(text, choices_dict)
I then tried the following code to try set a threshold:
title, index, score = process.extractOne(text, choices_dict, score_cutoff=80)
Which results in the following TypeError:
TypeError: cannot unpack non-iterable NoneType object
Finally, I also tried the following code:
title, index, scorer, score = process.extractOne(text, choices_dict, scorer=fuzz.token_sort_ratio, score_cutoff=80)
Which results in the following error:
ValueError: not enough values to unpack (expected 4, got 3)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当最佳分数低于
score_cutoff
时,process.extractOne
将返回 None。因此,您要么必须检查 None,要么捕获异常:或者
process.extractOne
will return None, when the best score is belowscore_cutoff
. So you either have to check for None, or catch the exception:or