Github user MLnick commented on a diff in the pull request:
https://github.com/apache/spark/pull/11844#discussion_r62798757
--- Diff: examples/src/main/python/ml/bisecting_k_means_example.py ---
@@ -36,21 +35,20 @@
.getOrCreate()
# $example on$
- data = spark.read.text("data/mllib/kmeans_data.txt").rdd
- parsed = data\
- .map(lambda row: Row(features=Vectors.dense([float(x) for x in
row.value.split(' ')])))
- training = spark.createDataFrame(parsed)
+ # Loads data.
+ dataset =
spark.read.format("libsvm").load("data/mllib/sample_kmeans_data.txt")
- kmeans =
BisectingKMeans().setK(2).setSeed(1).setFeaturesCol("features")
+ # Trains a bisecting k-means model.
+ bkm = BisectingKMeans().setK(2).setSeed(1)
+ model = bkm.fit(dataset)
- model = kmeans.fit(training)
+ # Evaluate clustering.
+ cost = model.computeCost(dataset)
+ print("Compute Cost = " + str(cost))
- # Evaluate clustering
- cost = model.computeCost(training)
- print("Bisecting K-means Cost = " + str(cost))
-
- centers = model.clusterCenters()
+ # Shows the result.
print("Cluster Centers: ")
+ centers = model.clusterCenters()
--- End diff --
Here we don't print `cluster center i` as we do in the Java and Scala
examples. I think we should make everything consistent between the 3 examples,
and also with the KMeans examples (which all don't print the "i" part, they
simply print out the centers).
I don't have a strong opinion either way, but it may be simpler to just
update the Java and Scala examples here to only print out the cluster centers
(which will make them consistent with this Python example and the 3 KMeans
examples)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]