Github user hhbyyh commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18538#discussion_r133571846
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/evaluation/ClusteringEvaluator.scala 
---
    @@ -0,0 +1,240 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.ml.evaluation
    +
    +import org.apache.spark.SparkContext
    +import org.apache.spark.annotation.Experimental
    +import org.apache.spark.broadcast.Broadcast
    +import org.apache.spark.ml.linalg.{BLAS, DenseVector, Vector, Vectors, 
VectorUDT}
    +import org.apache.spark.ml.param.{Param, ParamMap, ParamValidators}
    +import org.apache.spark.ml.param.shared.{HasFeaturesCol, HasPredictionCol}
    +import org.apache.spark.ml.util.{DefaultParamsReadable, 
DefaultParamsWritable, Identifiable, SchemaUtils}
    +import org.apache.spark.sql.{DataFrame, Dataset}
    +import org.apache.spark.sql.functions.{avg, col, udf}
    +import org.apache.spark.sql.types.IntegerType
    +
    +/**
    + * Evaluator for clustering results.
    + * At the moment, the supported metrics are:
    + *  squaredSilhouette: silhouette measure using the squared Euclidean 
distance;
    + *  cosineSilhouette: silhouette measure using the cosine distance.
    + *  The implementation follows the proposal explained
    + * <a 
href="https://drive.google.com/file/d/0B0Hyo%5f%5fbG%5f3fdkNvSVNYX2E3ZU0/view";>
    + *   in this document</a>.
    + */
    +@Experimental
    +class ClusteringEvaluator (val uid: String)
    +  extends Evaluator with HasPredictionCol with HasFeaturesCol with 
DefaultParamsWritable {
    +
    +  def this() = this(Identifiable.randomUID("SquaredEuclideanSilhouette"))
    +
    +  override def copy(pMap: ParamMap): ClusteringEvaluator = 
this.defaultCopy(pMap)
    +
    +  override def isLargerBetter: Boolean = true
    +
    +  /** @group setParam */
    +  def setPredictionCol(value: String): this.type = set(predictionCol, 
value)
    +
    +  /** @group setParam */
    +  def setFeaturesCol(value: String): this.type = set(featuresCol, value)
    +
    +  /**
    +   * param for metric name in evaluation
    +   * (supports `"squaredSilhouette"` (default))
    +   * @group param
    +   */
    +  val metricName: Param[String] = {
    +    val allowedParams = ParamValidators.inArray(Array("squaredSilhouette"))
    --- End diff --
    
    Yes, the idea often crosses my mind.
    Even though there's a claim that [K-Means is for Euclidean distances 
only](https://stats.stackexchange.com/questions/81481/why-does-k-means-clustering-algorithm-use-only-euclidean-distance-metric),
 I often see people has the requirement for custom distance computation in 
practice. So I would like to see KMeans support it.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to