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

    https://github.com/apache/spark/pull/10231#discussion_r47164981
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/tree/impl/RandomForest.scala ---
    @@ -842,60 +842,63 @@ private[ml] object RandomForest extends Logging {
             1.0
           }
           logDebug("fraction of data used for calculating quantiles = " + 
fraction)
    -      input.sample(withReplacement = false, fraction, new 
XORShiftRandom(seed).nextInt()).collect()
    +      input.sample(withReplacement = false, fraction, new 
XORShiftRandom(seed).nextInt())
         } else {
    -      new Array[LabeledPoint](0)
    +      input.sparkContext.emptyRDD[LabeledPoint]
         }
     
    -    val splits = new Array[Array[Split]](numFeatures)
    -
    -    // Find all splits.
    -    // Iterate over all features.
    -    var featureIndex = 0
    -    while (featureIndex < numFeatures) {
    -      if (metadata.isContinuous(featureIndex)) {
    -        val featureSamples = sampledInput.map(_.features(featureIndex))
    -        val featureSplits = findSplitsForContinuousFeature(featureSamples, 
metadata, featureIndex)
    +    findSplitsBinsBySorting(sampledInput, metadata, continuousFeatures)
    +  }
     
    -        val numSplits = featureSplits.length
    -        logDebug(s"featureIndex = $featureIndex, numSplits = $numSplits")
    -        splits(featureIndex) = new Array[Split](numSplits)
    +  private def findSplitsBinsBySorting(
    +      input: RDD[LabeledPoint],
    +      metadata: DecisionTreeMetadata,
    +      continuousFeatures: IndexedSeq[Int]): Array[Array[Split]] = {
    +
    +    val continuousSplits = {
    +      // reduce the parallelism for split computations when there are less
    +      // continuous features than input partitions. this prevents tasks 
from
    +      // being spun up that will definitely do no work.
    +      val numPartitions = math.min(continuousFeatures.length, 
input.partitions.length)
    +
    +      input
    +        .flatMap(point => continuousFeatures.map(idx => (idx, 
point.features(idx))))
    +        .groupByKey(numPartitions)
    +        .map { case (idx, samples) =>
    +          val thresholds = findSplitsForContinuousFeature(samples.toArray, 
metadata, idx)
    +          val splits: Array[Split] = thresholds.map(thresh => new 
ContinuousSplit(idx, thresh))
    --- End diff --
    
    (as mentioned in jenkins): scala style long line


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