-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-16957][MLlib] Use midpoints for split values. #17556
Changes from 20 commits
45b7493
c49d3ae
387eb49
2e68f1e
6a5806f
7ad590d
0aaed66
c07ffac
9ca5750
b74702a
76f4ae8
031c61a
1459b14
a094029
7c50d4a
7bb11dd
ae0e48e
59866fa
10037ea
1cae998
92df1c8
591d790
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -996,7 +996,7 @@ private[spark] object RandomForest extends Logging { | |
require(metadata.isContinuous(featureIndex), | ||
"findSplitsForContinuousFeature can only be used to find splits for a continuous feature.") | ||
|
||
val splits = if (featureSamples.isEmpty) { | ||
val splits: Array[Double] = if (featureSamples.isEmpty) { | ||
Array.empty[Double] | ||
} else { | ||
val numSplits = metadata.numSplits(featureIndex) | ||
|
@@ -1009,10 +1009,17 @@ private[spark] object RandomForest extends Logging { | |
// sort distinct values | ||
val valueCounts = valueCountMap.toSeq.sortBy(_._1).toArray | ||
|
||
// 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) { | ||
// if possible splits is not enough or just enough, just return all possible splits | ||
val splits = for { | ||
i <- 0 until possibleSplits | ||
} yield (valueCounts(i)._1 + valueCounts(i + 1)._1) / 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @srowen Is it more efficient than sliding? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. Maybe even just |
||
|
||
splits.toArray | ||
} else { | ||
// stride between splits | ||
val stride: Double = numSamples.toDouble / (numSplits + 1) | ||
|
@@ -1037,7 +1044,10 @@ private[spark] object RandomForest extends Logging { | |
// makes the gap between currentCount and targetCount smaller, | ||
// previous value is a split threshold. | ||
if (previousGap < currentGap) { | ||
splitsBuilder += valueCounts(index - 1)._1 | ||
val pre = valueCounts(index - 1) | ||
val cur = valueCounts(index) | ||
// perhaps weighted mean will be used later, see SPARK-16957 and Github PR 17556. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments like these tend to just get left around and sit there forever. Unless we file a new JIRA that intends to decide on future behavior, I would like to remove this comment altogether. I'd prefer to just remove it and not create a follow up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
splitsBuilder += (pre._1 + cur._1) / 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meh, could likewise be one line like above. No big deal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! revised. |
||
targetCount += stride | ||
} | ||
index += 1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code block is too long and has 4 exits. Emphasizing its type perhaps is better to be understand, though
splits
is implied by return type.