-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-14516][FOLLOWUP] Adding ClusteringEvaluator to examples #19676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| // $example on$ | ||
| import org.apache.spark.ml.clustering.KMeansModel; | ||
| import org.apache.spark.ml.clustering.KMeans; | ||
| import org.apache.spark.ml.evaluation.ClusteringEvaluator; | ||
| import org.apache.spark.ml.linalg.Vector; | ||
| import org.apache.spark.sql.Dataset; | ||
| import org.apache.spark.sql.Row; | ||
|
|
@@ -51,9 +52,17 @@ public static void main(String[] args) { | |
| KMeans kmeans = new KMeans().setK(2).setSeed(1L); | ||
| KMeansModel model = kmeans.fit(dataset); | ||
|
|
||
| // Evaluate clustering by computing Within Set Sum of Squared Errors. | ||
| double WSSSE = model.computeCost(dataset); | ||
| System.out.println("Within Set Sum of Squared Errors = " + WSSSE); | ||
| // Make predictions | ||
| Dataset<Row> predictions = model.transform(dataset); | ||
|
|
||
| // Evaluate clustering by computing Silhouette score | ||
| ClusteringEvaluator evaluator = new ClusteringEvaluator() | ||
| .setFeaturesCol("features") | ||
| .setPredictionCol("prediction") | ||
| .setMetricName("silhouette"); | ||
|
|
||
| double silhouette = evaluator.evaluate(predictions); | ||
| System.out.println("Silhouette with squared euclidean distance = " + silhouette); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. euclidean -> Euclidean, but not important to change unless you're touching the code again anyway
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I don't think I am changing the code again, but I can fix this grammatical error if you want. |
||
|
|
||
| // Shows the result. | ||
| Vector[] centers = model.clusterCenters(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use default values here, so it's not necessary to set them explicitly. We should keep examples as simple as possible. Thanks.