srowen commented on a change in pull request #25802: [SPARK-29095][ML] add 
extractInstances
URL: https://github.com/apache/spark/pull/25802#discussion_r325702663
 
 

 ##########
 File path: mllib/src/main/scala/org/apache/spark/ml/Predictor.scala
 ##########
 @@ -62,6 +62,40 @@ private[ml] trait PredictorParams extends Params
     }
     SchemaUtils.appendColumn(schema, $(predictionCol), DoubleType)
   }
+
+  /**
+   * Extract [[labelCol]], weightCol(if any) and [[featuresCol]] from the 
given dataset,
+   * and put it in an RDD with strong types.
+   */
+  protected def extractInstances(dataset: Dataset[_]): RDD[Instance] = {
+    val w = this match {
+      case p: HasWeightCol =>
+        if (isDefined(p.weightCol) && $(p.weightCol).nonEmpty) {
+          col($(p.weightCol)).cast(DoubleType)
+        } else {
+          lit(1.0)
+        }
+      case _ => lit(1.0)
 
 Review comment:
   If it doesn't have a weight column, does it mean there's no point in 
selecting lit(1.0) as a weight column as it will be unused? or do some 
algorithms not have a weight column but nevertheless have ways of using a 
weight?

----------------------------------------------------------------
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