【发布时间】:2018-07-15 13:16:22
【问题描述】:
假设我有以下变量
ChicKen120
Chicken1.20
Chicken(1.20)
Cow
cow.
cow/
cat
如您所见,有很多错别字。 我想做的是将相似的单词分组并自动重新定义每个组。
即
group 1 = "Cow", "cow", "cow/2
group 2 = "ChicKen120", "Chicken1.20"
格式化每个组后,最终结果将是
chicken(1.20)
chicken(1.20)
chicken(1.20)
cow
cow
cow
cat
我目前的进度
我通过adist()找到了相似词组
#Run adist on to find all words that are similar to another words.
text <- c("ChicKen120","Chicken1.20","Chicken(1.20)","Cow","cow.", "cow/", "cat")
> adist(text)
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 0 2 4 9 9 9 9
[2,] 2 0 2 10 9 10 10
[3,] 4 2 0 12 11 12 12
[4,] 9 10 12 0 2 2 3
[5,] 9 9 11 2 0 1 3
[6,] 9 10 12 2 1 0 3
[7,] 9 10 12 3 3 3 0
如你所见,相似词的距离小于4,不相似的词的距离大于4。
如何将这些结果聚类到可以重新定义的组中?
例如,我得到了以下建议:
“我使用 lapply() 和 unique() 对这个特征进行聚类。之后,我只是寻找质心并使用 table( ) 用于评分,就像检索互联网信息系统一样。例如:
“chocolate”、“chcolate”、“chocolatebar”、“choc bar”、“chocolate bar”都会自动重新识别为“chocolate”。
所有这些都是用原生库完成的。”
但是,我是 R 的初学者和数学的外行,所以我不知道如何处理组的聚类和重新定义。
【问题讨论】:
标签: r grouping cluster-analysis hierarchical-clustering