Skip to content

Commit

Permalink
[SPARK-31768][ML][FOLLOWUP] add getMetrics in Evaluators: cleanup
Browse files Browse the repository at this point in the history
### 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 #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 <ruifengz@foxmail.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
  • Loading branch information
zhengruifeng authored and WeichenXu123 committed Jan 26, 2021
1 parent d1177b5 commit cb37c96
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -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(
Expand Down

0 comments on commit cb37c96

Please sign in to comment.