MMA*_*ASS 8 python runtime levenshtein-distance fuzzywuzzy
我在 Python 中使用 Fuzzywuzzy 来匹配 2 个列表中的人名。但是,运行时间太长,因为一个列表包含 25000 个名称,另一个包含 39000 个名称。它已经运行了20个小时。
以前,我使用相同的代码来匹配具有 6000 和 3000 个名称的 2 个列表,运行时间为 1 小时。基于此,我当前工作的运行时间将需要 50 多个小时。
下面是我的代码:
names_array=[]
ratio_array=[]
def match_names(wrong_names,correct_names):
for row in wrong_names:
x=process.extractOne(row, correct_names, scorer=fuzz.token_set_ratio)
names_array.append(x[0])
ratio_array.append(x[1])
return names_array,ratio_array
df=pd.read_csv("wrong-country-names.csv",encoding="ISO-8859-1")
wrong_names=df['name'].dropna().values
choices_df=pd.read_csv("country-names.csv",encoding="ISO-8859-1")
correct_names=choices_df['name'].values
name_match,ratio_match=match_names(wrong_names,correct_names)
Run Code Online (Sandbox Code Playgroud)
我fuzz.token_set_ratio
根据我拥有的数据选择作为得分手来执行这场多对多比赛。
下面是示例数据:
wrong_names = ['Alberto Steve', 'David Lee']
correct_names = ['Alberto Lee Steve', 'David Steve Lee']
Run Code Online (Sandbox Code Playgroud)
基本上,错误名称列表不包含中间名,为了忽略这一点并生成合理的匹配,我选择了fuzz.token_set_ratio
.
通过在线研究,我找到了一个安装 python levenshtein 包的解决方案,以将运行时间加快 4-10 倍。但是,我的工作现在已经运行了 20 多个小时,我不想破坏当前的工作,所以我会在这之后尝试一下。
我想知道是否还有其他选择可以改善这一点。
提前致谢。