zhengruifeng 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_r364536142
##########
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:
I guess we should suggest end uers NOT to cache input DFs/RDDs, and the
impls should always cache necessary internal DFs/RDDs.
Some time user caching DFs outside of impl will not help performance too
much, for example in decision tree, vectors will be convert to treepoints, and
then the cached vectors are not used any more.
----------------------------------------------------------------
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]