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

    https://github.com/apache/spark/pull/1673#discussion_r15628238
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/tree/DecisionTree.scala ---
    @@ -845,33 +842,15 @@ object DecisionTree extends Serializable with Logging 
{
                 }
               }
     
    -          if (leftTotalCount == 0) {
    -            return new InformationGainStats(0, topImpurity, topImpurity, 
Double.MinValue, 1)
    -          }
    -          if (rightTotalCount == 0) {
    -            return new InformationGainStats(0, topImpurity, 
Double.MinValue, topImpurity, 1)
    -          }
    -
    -          val leftImpurity = strategy.impurity.calculate(leftCounts, 
leftTotalCount)
    -          val rightImpurity = strategy.impurity.calculate(rightCounts, 
rightTotalCount)
    -
    -          val leftWeight = leftTotalCount / (leftTotalCount + 
rightTotalCount)
    -          val rightWeight = rightTotalCount / (leftTotalCount + 
rightTotalCount)
    -
    -          val gain = {
    -            if (level > 0) {
    -              impurity - leftWeight * leftImpurity - rightWeight * 
rightImpurity
    -            } else {
    -              impurity - leftWeight * leftImpurity - rightWeight * 
rightImpurity
    -            }
    -          }
    -
               val totalCount = leftTotalCount + rightTotalCount
    +          if (totalCount == 0) {
    +            // Return arbitrary prediction.
    +            return new InformationGainStats(0, topImpurity, topImpurity, 
topImpurity, 0)
    +          }
     
               // Sum of count for each label
    -          val leftRightCounts: Array[Double]
    -            = leftCounts.zip(rightCounts)
    -              .map{case (leftCount, rightCount) => leftCount + rightCount}
    +          val leftRightCounts: Array[Double] = 
leftCounts.zip(rightCounts).map {
    +              case (leftCount, rightCount) => leftCount + rightCount }
    --- End diff --
    
    It may be more consistent to write this way:
    
    ~~~
    val leftRightCounts: Array[Double] =
      leftCounts.zip(rightCounts).map { case (leftCount, rightCount) =>
        leftCount + rightCount
      }
    ~~~


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

Reply via email to