-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-13444] [MLlib] QuantileDiscretizer chooses bad splits on large DataFrames #11319
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
635fb4e
fixed splits bug in QuantileDiscretizer
d5dbaa2
explicitly cast requiredSamples to Double
4892fb7
added minSamplesRequired parameter to QuantileDiscretizer
3b55b60
test for QuantileDiscretizer on large datasets
c0052e4
private-tize minSamplesRequired; updated comments
abea876
change QuantileDiscretizer test name to better reflect purpose
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,26 @@ class QuantileDiscretizerSuite | |
| } | ||
| } | ||
|
|
||
| test("Test splits on relatively large dataset") { | ||
| val sqlCtx = SQLContext.getOrCreate(sc) | ||
| import sqlCtx.implicits._ | ||
|
|
||
| val datasetSize = QuantileDiscretizer.minSamplesRequired + 1 | ||
| val numBuckets = 5 | ||
| val df = sc.parallelize((1.0 to datasetSize by 1.0).map(Tuple1.apply)).toDF("input") | ||
| val discretizer = new QuantileDiscretizer() | ||
| .setInputCol("input") | ||
| .setOutputCol("result") | ||
| .setNumBuckets(numBuckets) | ||
| .setSeed(1) | ||
|
Author
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. This is the offending line |
||
|
|
||
| val result = discretizer.fit(df).transform(df) | ||
| val observedNumBuckets = result.select("result").distinct.count | ||
|
|
||
| assert(observedNumBuckets === numBuckets, | ||
| "Observed number of buckets does not equal expected number of buckets.") | ||
| } | ||
|
|
||
| test("read/write") { | ||
| val t = new QuantileDiscretizer() | ||
| .setInputCol("myInputCol") | ||
|
|
||
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.
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 test will require creating a dataset at least as large as
minSamplesRequired, so making its value excessively large could slow down testing.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.
less rows -> fewer rows
entire dataset column -> entire dataset?
10000 just isn't that big. A dummy data set in a test would be, what, a megabyte in memory? Am I missing a bigger problem there?
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.
I don't think you're missing anything. It's my first time contributing and I just want to be explicit for reviewers of the patch. I agree that 10K isn't that big, especially out "in the wild". However, I wasn't sure if there were standards for time/memory consumption for tests so I added the line note so that reviewers with more experience than me would be aware in case there are established/de facto testing standards.
I'll make the "->" changes you've indicated and push a new commit sometime today. Thanks.
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.
Also, my original reason for asking about removing the hard coded value of 10K was because that value was partly the cause of the bug and so a regression test would need to know the value.
I could have hard coded 10k in to my test. However if a developer increased its value later, say to 100K, without increasing the hard coded test value as well, they would render the test useless since it would always pass.
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.
Yeah we have muuuch bigger tests that turn up whole small clusters. Making a little data set is fine. You can expose the 10000 figure as a
private[spark] valin theobjectso you can reference it from test code.