我有一个维基页面(棒球,曲棍球,音乐,足球)的语料库,我通过tfidf
,然后通过kmeans
运行。在几个问题开始后(你可以看到我以前的问题),我终于得到了一个KMeansModel
...但是当我尝试predict
时,我一直得到相同的中心。这是因为小数据集,还是因为我正在比较多个单词文档与较少量的单词(1-20)查询?还是有什么我做错了?请参见下面的代码:K-Means集群偏向一个中心
//Preprocessing of data includes splitting into words
//and removing words with only 1 or 2 characters
val corpus: RDD[Seq[String]]
val hashingTF = new HashingTF(100000)
val tf = hashingTF.transform(corpus)
val idf = new IDF().fit(tf)
val tfidf = idf.transform(tf).cache
val kMeansModel = KMeans.train(tfidf, 3, 10)
val queryTf = hashingTF.transform(List("music"))
val queryTfidf = idf.transform(queryTf)
kMeansModel.predict(queryTfidf) //Always the same, no matter the term supplied
这个问题似乎有点相关this one
谢谢!我今晚试试这些建议。 –
@JustinPihony它有用吗? – zero323