Github user imatiach-msft commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16722#discussion_r99054576
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/regression/DecisionTreeRegressor.scala 
---
    @@ -99,16 +105,31 @@ class DecisionTreeRegressor @Since("1.4.0") 
(@Since("1.4.0") override val uid: S
       @Since("2.0.0")
       def setVarianceCol(value: String): this.type = set(varianceCol, 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("2.2.0")
    +  def setWeightCol(value: String): this.type = set(weightCol, value)
    +
       override protected def train(dataset: Dataset[_]): 
DecisionTreeRegressionModel = {
         val categoricalFeatures: Map[Int, Int] =
           MetadataUtils.getCategoricalFeatures(dataset.schema($(featuresCol)))
    -    val oldDataset: RDD[LabeledPoint] = extractLabeledPoints(dataset)
    +    val w = if (!isDefined(weightCol) || $(weightCol).isEmpty) lit(1.0) 
else col($(weightCol))
    +    val instances =
    +      dataset.select(col($(labelCol)).cast(DoubleType), w, 
col($(featuresCol))).rdd.map {
    +        case Row(label: Double, weight: Double, features: Vector) =>
    +          Instance(label, weight, features)
    +      }
    --- End diff --
    
    the code above looks the same as the classifier, can we refactor somehow:
    
        val w = if (!isDefined(weightCol) || $(weightCol).isEmpty) lit(1.0) 
else col($(weightCol)) 
        val instances = 
          dataset.select(col($(labelCol)).cast(DoubleType), w, 
col($(featuresCol))).rdd.map { 
            case Row(label: Double, weight: Double, features: Vector) => 
              Instance(label, weight, features) 



---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to