This is an automated email from the ASF dual-hosted git repository.

weichenxu123 pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 4cf94f3  [SPARK-31768][ML][FOLLOWUP] add getMetrics in Evaluators: 
cleanup
4cf94f3 is described below

commit 4cf94f3e33de968b0048690cb0128437736d60a7
Author: Ruifeng Zheng <ruife...@foxmail.com>
AuthorDate: Tue Jan 26 11:57:28 2021 +0800

    [SPARK-31768][ML][FOLLOWUP] add getMetrics in Evaluators: cleanup
    
    ### What changes were proposed in this pull request?
    1, make `silhouette` a method;
    2, change return type of `setDistanceMeasure` to `this.type`;
    
    ### Why are the changes needed?
    see comments in https://github.com/apache/spark/pull/28590
    
    ### Does this PR introduce _any_ user-facing change?
    No, 3.1 has not been released
    
    ### How was this patch tested?
    existing testsuites
    
    Closes #31334 from zhengruifeng/31768-followup.
    
    Authored-by: Ruifeng Zheng <ruife...@foxmail.com>
    Signed-off-by: Weichen Xu <weichen...@databricks.com>
    (cherry picked from commit cb37c962bec25083a67d65387ed88e7d4ee556ca)
    Signed-off-by: Weichen Xu <weichen...@databricks.com>
---
 .../scala/org/apache/spark/ml/evaluation/ClusteringMetrics.scala | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git 
a/mllib/src/main/scala/org/apache/spark/ml/evaluation/ClusteringMetrics.scala 
b/mllib/src/main/scala/org/apache/spark/ml/evaluation/ClusteringMetrics.scala
index 3dea244..3035688 100644
--- 
a/mllib/src/main/scala/org/apache/spark/ml/evaluation/ClusteringMetrics.scala
+++ 
b/mllib/src/main/scala/org/apache/spark/ml/evaluation/ClusteringMetrics.scala
@@ -37,13 +37,18 @@ class ClusteringMetrics private[spark](dataset: Dataset[_]) 
{
 
   def getDistanceMeasure: String = distanceMeasure
 
-  def setDistanceMeasure(value: String) : Unit = distanceMeasure = value
+  def setDistanceMeasure(value: String) : this.type = {
+    require(value.equalsIgnoreCase("squaredEuclidean") ||
+      value.equalsIgnoreCase("cosine"))
+    distanceMeasure = value
+    this
+  }
 
   /**
    * Returns the silhouette score
    */
   @Since("3.1.0")
-  lazy val silhouette: Double = {
+  def silhouette(): Double = {
     val columns = dataset.columns.toSeq
     if (distanceMeasure.equalsIgnoreCase("squaredEuclidean")) {
       SquaredEuclideanSilhouette.computeSilhouetteScore(


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to