2016-06-07 112 views
0

我試圖做一些與此問題非常相似的事情: How to initialize cluster centers for K-means in Spark MLlib? 但是,我並不完全瞭解該解決方案。當我嘗試加入更多的重心,我得到一個錯誤:在Spark中初始化羣集中心

Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: mismatched cluster count

我用

val initialModel = new KMeansModel(
    Array("[0.6, 0.6, 5.0]", "[8.0, 8.0, 1.0]", "[11, 9.0, 7.0]").map(Vectors.parse(_)) 
) 
val model = new KMeans() 
    .setInitialModel(initialModel) 
    .setK(3) 
    .run(data) 
+0

的可能的複製[如何初始化在星火MLlib K-均值聚類中心?(http://stackoverflow.com/questions/35426240/how-to-initialize-cluster-centers-for-k -means功能於火花mllib) – gsamaras

回答

0

默認情況下,KMEANS集K爲2。這是因爲設置初始前設置K容易模型(KMeansModel.k和KMeans.k必須重合)。

val initialModel = new KMeansModel(
    Array("[0.6, 0.6, 5.0]", "[8.0, 8.0, 1.0]", "[11, 9.0, 7.0]").map(Vectors.parse(_)) 
) 

val model = new KMeans() 
    .setK(3) 
    .setInitialModel(initialModel) 
    .run(data)