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

    https://github.com/apache/spark/pull/503#discussion_r11935731
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/tree/DecisionTree.scala ---
    @@ -82,32 +80,32 @@ class DecisionTree (private val strategy: Strategy) 
extends Serializable with Lo
          * still survived the filters of the parent nodes.
          */
     
    -    // TODO: Convert for loop to while loop
    -    breakable {
    -      for (level <- 0 until maxDepth) {
    -
    -        logDebug("#####################################")
    -        logDebug("level = " + level)
    -        logDebug("#####################################")
    -
    -        // Find best split for all nodes at a level.
    -        val splitsStatsForLevel = DecisionTree.findBestSplits(input, 
parentImpurities, strategy,
    -          level, filters, splits, bins)
    -
    -        for ((nodeSplitStats, index) <- 
splitsStatsForLevel.view.zipWithIndex) {
    -          // Extract info for nodes at the current level.
    -          extractNodeInfo(nodeSplitStats, level, index, nodes)
    -          // Extract info for nodes at the next lower level.
    -          extractInfoForLowerLevels(level, index, maxDepth, 
nodeSplitStats, parentImpurities,
    -            filters)
    -          logDebug("final best split = " + nodeSplitStats._1)
    -        }
    -        require(scala.math.pow(2, level) == splitsStatsForLevel.length)
    -        // Check whether all the nodes at the current level at leaves.
    -        val allLeaf = splitsStatsForLevel.forall(_._2.gain <= 0)
    -        logDebug("all leaf = " + allLeaf)
    -        if (allLeaf) break // no more tree construction
    +    var level = 0
    +    var break = false
    +    while (level < maxDepth && !break) {
    +
    +      logDebug("#####################################")
    +      logDebug("level = " + level)
    +      logDebug("#####################################")
    +
    +      // Find best split for all nodes at a level.
    +      val splitsStatsForLevel = DecisionTree.findBestSplits(input, 
parentImpurities, strategy,
    +        level, filters, splits, bins)
    +
    +      for ((nodeSplitStats, index) <- 
splitsStatsForLevel.view.zipWithIndex) {
    +        // Extract info for nodes at the current level.
    +        extractNodeInfo(nodeSplitStats, level, index, nodes)
    +        // Extract info for nodes at the next lower level.
    +        extractInfoForLowerLevels(level, index, maxDepth, nodeSplitStats, 
parentImpurities,
    +          filters)
    +        logDebug("final best split = " + nodeSplitStats._1)
           }
    +      require(scala.math.pow(2, level) == splitsStatsForLevel.length)
    +      // Check whether all the nodes at the current level at leaves.
    +      val allLeaf = splitsStatsForLevel.forall(_._2.gain <= 0)
    +      logDebug("all leaf = " + allLeaf)
    +      if (allLeaf) break = true // no more tree construction
    --- End diff --
    
    per Spark style guide, can you change this to include curly braces, e.g.
    ```scala
    if (allLeaf) {
      break = true
    } else {
      level += 1
    }
    ```
    
    Thanks.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to