【问题标题】:How to increase the speed of calculate string similarity score within dataframe?如何提高数据框中字符串相似度得分的计算速度?
【发布时间】:2019-04-24 18:01:27
【问题描述】:

我有一个如下的数据框:

df = pd.DataFrame(data=[[1, 'Berlin',], [2, 'Paris', ],
                    [3, 'Lausanne', ], [4, 'Bayswater',],
                    [5, 'Table Bay', ], [6, 'Bejing',],
                    [7, 'Bombay',], [8, 'About the IIS']],
                    columns=['id', 'text'],)

我想使用库 jellyfish 中的 jaro_winkler 来计算每个字符串的相似度分数,并与其余所有字符串进行比较,并输出最相似的一个或得到相似度分数矩阵如下:

      str1 str2 str3
str1    1   0.6  0.7
str2    0.6  1   0.3
str3    0.7  0.3  1

我怎样才能以最快的方式得到这个结果。现在我只是使用循环来比较每一个并将结果存储在列表中。

 def sim_cal(string1, string2):
     similar = jellyfish.jaro_winkler(string1, string2)
     return similar

但是如果数据变大速度会很慢,那有什么办法可以加快速度呢?

谢谢。

【问题讨论】:

    标签: python pandas nlp similarity


    【解决方案1】:

    使用Gensim,您可以执行this 之类的操作。

    我在这个定时示例中使用了GloVe

    不会说谎,这很有趣。

    【讨论】:

    • 感谢您的回答,但它s not influenced by the way calculate the similarity score, I use my way what I post also the time consuming for each pair of strings similar as yours.
    猜你喜欢
    • 2011-10-03
    • 2018-03-08
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 2013-06-06
    • 2013-02-24
    • 2011-04-04
    • 2011-12-10
    相关资源
    最近更新 更多