Skip to content

Commit d005493

Browse files
committed
Example code for Power Iteration Clustering
1 parent 8c3025e commit d005493

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

examples/src/main/scala/org/apache/spark/examples/ml/PowerIterationClusteringExample.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,21 @@ object PowerIterationClusteringExample {
4141

4242
// $example on$
4343
val dataset = spark.createDataFrame(Seq(
44-
(0L, Array(1L, 2L, 4L), Array(0.9, 0.9, 0.1)),
45-
(1L, Array(0L, 2L), Array(0.9, 0.9)),
46-
(2L, Array(0L, 1L), Array(0.9, 0.9)),
47-
(3L, Array(4L), Array(0.9)),
48-
(4L, Array(0L, 3L), Array(0.1, 0.9))
49-
)).toDF("id", "neighbors", "similarities")
44+
(0L, 1L, 1.0),
45+
(0L, 2L, 1.0),
46+
(1L, 2L, 1.0),
47+
(3L, 4L, 1.0),
48+
(4L, 0L, 0.1)
49+
)).toDF("src", "dst", "weight")
5050

5151
// Trains a PIC model.
5252
val model = new PowerIterationClustering().
5353
setK(2).
54+
setMaxIter(20).
5455
setInitMode("degree").
55-
setMaxIter(20)
56+
setWeightCol("weight")
5657

57-
val prediction = model.transform(dataset).select("id", "prediction")
58+
val prediction = model.assignClusters(dataset).select("id", "cluster")
5859

5960
// Shows the cluster assignment
6061
prediction.show()

0 commit comments

Comments
 (0)