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

    https://github.com/apache/spark/pull/21081#discussion_r181846789
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/clustering/KMeans.scala 
---
    @@ -123,8 +128,15 @@ class KMeansModel private[ml] (
       @Since("2.0.0")
       override def transform(dataset: Dataset[_]): DataFrame = {
         transformSchema(dataset.schema, logging = true)
    -    val predictUDF = udf((vector: Vector) => predict(vector))
    -    dataset.withColumn($(predictionCol), predictUDF(col($(featuresCol))))
    +    // val predictUDF = udf((vector: Vector) => predict(vector))
    +    if (dataset.schema($(featuresCol)).dataType.equals(new VectorUDT)) {
    --- End diff --
    
    tip: This can be more succinct if written as:
    ```
    val predictUDF = if (dataset.schema(...).dataType.equals(...)) { A } else { 
B }
    dataset.withColumn($(predictionCol), predictUDF(col($(featuresCol))))  // 
so this line is only written once
    ```


---

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

Reply via email to