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

    https://github.com/apache/spark/pull/10976#discussion_r52694928
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/feature/Binarizer.scala 
---
    @@ -62,28 +65,57 @@ final class Binarizer(override val uid: String)
       def setOutputCol(value: String): this.type = set(outputCol, value)
     
       override def transform(dataset: DataFrame): DataFrame = {
    -    transformSchema(dataset.schema, logging = true)
    +    val outputSchema = transformSchema(dataset.schema)
    +    val schema = dataset.schema
    +    val inputType = schema($(inputCol)).dataType
         val td = $(threshold)
    -    val binarizer = udf { in: Double => if (in > td) 1.0 else 0.0 }
    -    val outputColName = $(outputCol)
    -    val metadata = 
BinaryAttribute.defaultAttr.withName(outputColName).toMetadata()
    -    dataset.select(col("*"),
    -      binarizer(col($(inputCol))).as(outputColName, metadata))
    +
    +    val binarizerDouble = udf { in: Double => if (in > td) 1.0 else 0.0 }
    +    val binarizerVector = udf { (data: Vector) =>
    +      val indices = ArrayBuilder.make[Int]
    +      val values = ArrayBuilder.make[Double]
    +
    +      data.foreachActive { (index, value) =>
    +        indices += index
    +        values += (if (value > td) 1.0 else 0.0)
    +      }
    +
    +      data match {
    --- End diff --
    
    We can output `Vectors.sparse(data.size, indices.result(), 
values.result()).compressed` directly.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to