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

    https://github.com/apache/spark/pull/12374#discussion_r69824214
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/tree/impl/RandomForest.scala ---
    @@ -712,17 +712,23 @@ private[spark] object RandomForest extends Logging {
                 splitIndex += 1
               }
               // Find best split.
    -          val (bestFeatureSplitIndex, bestFeatureGainStats) =
    -            Range(0, numSplits).map { case splitIdx =>
    -              val leftChildStats = 
binAggregates.getImpurityCalculator(nodeFeatureOffset, splitIdx)
    -              val rightChildStats =
    -                binAggregates.getImpurityCalculator(nodeFeatureOffset, 
numSplits)
    -              rightChildStats.subtract(leftChildStats)
    -              gainAndImpurityStats = 
calculateImpurityStats(gainAndImpurityStats,
    -                leftChildStats, rightChildStats, binAggregates.metadata)
    -              (splitIdx, gainAndImpurityStats)
    -            }.maxBy(_._2.gain)
    -          (splits(featureIndex)(bestFeatureSplitIndex), 
bestFeatureGainStats)
    +          if (numSplits == 0) {
    --- End diff --
    
    This seems slightly hacky to me. What is your opinion about doing filtering 
out the feature indices that have zero splits (something similar to this)?
    
    ```scala
    val validFeaturesSplits = Range(0, 
binAggregates.metadata.numFeaturesPerNode).filter { featureIndexIdx =>
      val featureIndex = if (featuresForNode.nonEmpty) {
        featuresForNode.get.apply(featureIndexIdx)
      } else {
        featureIndexIdx
      }
      binAggregates.metadata.numSplits(featureIndex) != 0
    }
    ```
    
    That will prevent code-rewrite for this corner-case in PR's such as 
https://github.com/apache/spark/pull/13959 and 
https://github.com/apache/spark/pull/8540


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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to