将 Python 中的文本描述组合在一起

Grouping together text descriptions in Python

我有以下数据集:

data = pd.DataFrame({'Members':['Biology PhD student', 'Chemistry Master student', 'Engineering undergraduate student', 'Administration staff',                           
 'Reception staff', 'Research Associate Chemistry', 'Associate Statistics'], 'UCode':[1,1,1,2,2,1,1],'id':['aaa100','aaa121','aa123','bb212','bb214','aa111','aa109']})

data

             Members                     UCode  id
    0   Biology PhD student                1    aaa100
    1   Chemistry Master student           1    aaa121
    2   Engineering undergraduate student  1    aa123
    3   Administration staff               2    bb212
    4   Reception staff                    2    bb214
    5   Research Associate Chemistry       1    aa111
    6   Associate Statistics               1    aa109

其中 df.Members 列包含描述每个列出的成员的功能的字符串。

您建议使用哪种文本分析来仅使用 df.Members 列的信息(文本)来查找相似成员组?例如,在这个玩具示例中,分析应该 return 两个不同的组。我正在考虑 strings/words 的两个列表之间的相似性度量。 非常感谢任何 suggestion/help。 谢谢, 马可

您需要将 string 'Members' 转换为 word-vector,然后对这些向量执行 聚类 ,如果您不知道先验组数,或者分类任务,如果你知道 classes/groups.

的数量

我可以给你一些建议,我不是专家,但我找到了一个工具,可以在类似的情况下为我服务。 Gensim is a tool for python that support text analysis and some of the features help you find the topics in the documents. Check this 教程我认为它对你很有用。它会让您了解如何使用。 现在这些都是非常小的文件,所以我建议你寻找一些方法来改进对这种类型数据的分析,比如 biterms 之类的,因为它们的长度会给你带来一些问题。 希望对你有帮助。

简单的等字计数器,例如

from collections import Counter

WordCounter = Counter()
for text in members:
    words = text.split(' ')
    for word in words:
        WordCounter[word] += 1

print(WordCounter.most_common(3))

Output: [('student', 3), ('staff', 2), ('Associate', 2)]