我正在尝试做一些与此问题非常相似的事情: How to initialize cluster centers for K-means in Spark MLlib? 但是,我并不完全理解这个解决方案。当我尝试添加更多质心时,我收到错误:
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 :(得分: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)