我正在尝试创建Jaccard距离矩阵并对其执行K-means以发出群集ID和群集中元素的ID。它的输入是Twitter推文。以下是代码,我无法理解如何使用kmeans的文件中的初始种子。使用jaccard距离矩阵的Kmeans聚类
install.packages("rjson" ,dependencies=TRUE)
library("rjson")
install.packages("jsonlite" ,dependencies=TRUE)
library("jsonlite")
install.packages("stringdist" ,dependencies=TRUE)
library("stringdist")
data <- fromJSON(sprintf("[%s]", paste(readLines(file("C:\\Users\\Yuzuru Onathoshi\\Desktop\\Assignment5_pxv142730_sxl162530\\Part2\\Input\\Tweets.json")),collapse=",")))
t.feature <- data
t.feature$geo<-NULL
Jmatrix<-stringdistmatrix(t.feature$text,t.feature$text,method = "jaccard")
colnames(Jmatrix) <- t.feature$from_user_id
rownames(Jmatrix) <- t.feature$from_user_id
fit <- kmeans(Jmatrix, 10)
你可以实现自己的kmeans与jaccard的距离,它不应该是困难的。 –
@sandipan不正确。 k-means可能不会为其他距离收敛,除非您也用适当的函数替换平均值。 –
// @ Anony-Mousse真的吗?这有什么理论上的结果吗?它背后的数学直觉是什么?如果不意味着我们可以使用k-medoid类似的函数。尽管与kmeans具有相同的优化功能(只改变了距离度量),但直觉上我不明白为什么它不会收敛。 - sandipan 5小时前 –