srowen commented on a change in pull request #27035: [SPARK-30351][ML][PySpark] 
BisectingKMeans support instance weighting
URL: https://github.com/apache/spark/pull/27035#discussion_r363771852
 
 

 ##########
 File path: 
mllib/src/main/scala/org/apache/spark/ml/clustering/BisectingKMeans.scala
 ##########
 @@ -261,31 +264,50 @@ class BisectingKMeans @Since("2.0.0") (
   @Since("2.4.0")
   def setDistanceMeasure(value: String): this.type = set(distanceMeasure, 
value)
 
+  /**
+   * Sets the value of param [[weightCol]].
+   * If this is not set or empty, we treat all instance weights as 1.0.
+   * Default is not set, so all instances have weight one.
+   *
+   * @group setParam
+   */
+  @Since("3.0.0")
+  def setWeightCol(value: String): this.type = set(weightCol, value)
+
   @Since("2.0.0")
   override def fit(dataset: Dataset[_]): BisectingKMeansModel = instrumented { 
instr =>
     transformSchema(dataset.schema, logging = true)
 
     val handlePersistence = dataset.storageLevel == StorageLevel.NONE
-    val rdd = DatasetUtils.columnToOldVector(dataset, getFeaturesCol)
+    val w = if (isDefined(weightCol) && $(weightCol).nonEmpty) {
+      col($(weightCol)).cast(DoubleType)
+    } else {
+      lit(1.0)
+    }
+
+    val instances: RDD[(OldVector, Double)] = dataset
+      .select(DatasetUtils.columnToVector(dataset, getFeaturesCol), w).rdd.map 
{
+      case Row(point: Vector, weight: Double) => (OldVectors.fromML(point), 
weight)
+    }
     if (handlePersistence) {
 
 Review comment:
   The persistence strategy is inconsistent. I'd prefer to standardize it more 
than change it though. We want to avoid silently taking a big performance hit 
by not caching. Either that means warning the user or caching internal RDDs for 
the user.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to