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

    https://github.com/apache/spark/pull/13650#discussion_r67740952
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/regression/RandomForestRegressor.scala 
---
    @@ -168,15 +173,39 @@ class RandomForestRegressionModel private[ml] (
       // Note: We may add support for weights (based on tree performance) 
later on.
       private lazy val _treeWeights: Array[Double] = 
Array.fill[Double](_trees.length)(1.0)
     
    +  @Since("2.1.0")
    +  /** @group getParam */
    +  def setVarianceCol(value: String): this.type = set(varianceCol, value)
    +
       @Since("1.4.0")
       override def treeWeights: Array[Double] = _treeWeights
     
       override protected def transformImpl(dataset: Dataset[_]): DataFrame = {
         val bcastModel = dataset.sparkSession.sparkContext.broadcast(this)
    +
    +    var output = dataset
    +
         val predictUDF = udf { (features: Any) =>
           bcastModel.value.predict(features.asInstanceOf[Vector])
         }
    -    dataset.withColumn($(predictionCol), predictUDF(col($(featuresCol))))
    +    val predictions = predictUDF(col($(featuresCol)))
    +    output = dataset.withColumn($(predictionCol), predictions)
    +
    +    val varianceUDF = udf { (features: Any) =>
    +      val leafNodes = 
bcastModel.value.returnLeafNodes(features.asInstanceOf[Vector])
    +      leafNodes.map { leafNode =>
    --- End diff --
    
    I see that this and the decision tree variance functions rely on the fact 
that the only currently implemented impurity for regression is `Variance`. If 
anything else ever gets added then this function will be incorrect. We'll need 
to make sure that the unit tests will fail in such a case.


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