Github user facaiy commented on a diff in the pull request: https://github.com/apache/spark/pull/17556#discussion_r110385526 --- Diff: mllib/src/main/scala/org/apache/spark/ml/tree/impl/RandomForest.scala --- @@ -1009,10 +1009,24 @@ private[spark] object RandomForest extends Logging { // sort distinct values val valueCounts = valueCountMap.toSeq.sortBy(_._1).toArray + def weightedMean(pre: (Double, Int), cru: (Double, Int)): Double = { + val (preValue, preCount) = pre + val (curValue, curCount) = cru + (preValue * preCount + curValue * curCount) / (preCount + curCount) + } + // if possible splits is not enough or just enough, just return all possible splits val possibleSplits = valueCounts.length - 1 - if (possibleSplits <= numSplits) { - valueCounts.map(_._1).init + if (possibleSplits == 0) { + // constant feature + Array.empty[Double] + + } else if (possibleSplits <= numSplits) { + valueCounts + .sliding(2) + .map{x => weightedMean(x(0), x(1))} --- End diff -- fixed. Do you mean use `scanLeft`? It's a little complicate and obscure.
--- 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