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-30938][ML][MLLIB] BinaryClassificationMetrics optimization #27682
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testCode: import org.apache.spark.mllib.evaluation.BinaryClassificationMetrics
import scala.util.Random
import org.apache.spark.mllib.evaluation.BinaryClassificationMetrics
import scala.util.Random
val scoreAndLabels = sc.range(0, 40000000L, 1, 4).mapPartitionsWithIndex{ case (pid, iter) => val rng=new Random(pid); iter.map{_ => (rng.nextDouble, rng.nextInt(2).toDouble)} }
scoreAndLabels.count
val metrics = new BinaryClassificationMetrics(scoreAndLabels, 1)
val start = System.currentTimeMillis; val auc = metrics.areaUnderROC; val end = System.currentTimeMillis; end - start
result:
|
zhengruifeng
commented
Feb 24, 2020
if (grouping < 2) { | ||
// numBins was more than half of the size; no real point in down-sampling to bins | ||
logInfo(s"Curve is too small ($countsSize) for $numBins bins to be useful") | ||
counts | ||
} else { | ||
if (grouping >= Int.MaxValue) { |
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.
Iterator.grouped(size: Int)
does not support grouping
larger than Int.MaxValue
After this change, BinaryClassificationMetrics
can deal with grouping
larger than Int.MaxValue
Test build #118863 has finished for PR 27682 at commit
|
Merged to master |
sjincho
pushed a commit
to sjincho/spark
that referenced
this pull request
Apr 15, 2020
### What changes were proposed in this pull request? 1, avoid `Iterator.grouped(size: Int)`, which need to maintain an arraybuffer of `size` 2, keep the number of partitions in curve computation ### Why are the changes needed? 1, `BinaryClassificationMetrics` tend to fail (OOM) when `grouping=count/numBins` is too large, due to `Iterator.grouped(size: Int)` need to maintain an arraybuffer with `size` entries, however, in `BinaryClassificationMetrics` we do not need to maintain such a big array; 2, make sizes of partitions more even; This PR computes metrics more stable and a littler faster; ### Does this PR introduce any user-facing change? No ### How was this patch tested? existing testsuites Closes apache#27682 from zhengruifeng/grouped_opt. Authored-by: zhengruifeng <ruifengz@foxmail.com> Signed-off-by: zhengruifeng <ruifengz@foxmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
1, avoid
Iterator.grouped(size: Int)
, which need to maintain an arraybuffer ofsize
2, keep the number of partitions in curve computation
Why are the changes needed?
1,
BinaryClassificationMetrics
tend to fail (OOM) whengrouping=count/numBins
is too large, due toIterator.grouped(size: Int)
need to maintain an arraybuffer withsize
entries, however, inBinaryClassificationMetrics
we do not need to maintain such a big array;2, make sizes of partitions more even;
This PR computes metrics more stable and a littler faster;
Does this PR introduce any user-facing change?
No
How was this patch tested?
existing testsuites