-
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-22799][ML] Bucketizer should throw exception if single- and multi-column params are both set #19993
Closed
Closed
[SPARK-22799][ML] Bucketizer should throw exception if single- and multi-column params are both set #19993
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8f3581c
[SPARK-22799][ML] Bucketizer should throw exception if single- and mu…
mgaido91 bb0c0d2
address comments
mgaido91 9f56800
fix doc
mgaido91 f593f5b
fix mima error
mgaido91 2ecdc73
use ParamValidators
mgaido91 26fe05e
fix ut
mgaido91 64634b5
address review comments
mgaido91 9872bfd
add checkMultiColumnParams
mgaido91 d0b8d06
address review comments
mgaido91 b20fb91
remove two unneeded checks
mgaido91 09d652d
address comments
mgaido91 a0c0fed
remove isBucketizeMultipleColumns
mgaido91 25b9bd4
address comments
mgaido91 18bbf61
strengthened requirements about exclusive Params for single and multi…
jkbradley d9d25b0
Merge pull request #1 from jkbradley/mgaido91-SPARK-22799
mgaido91 8c162a3
fix style error
mgaido91 7894609
fixt ut error
mgaido91 ebc6d16
add all cases to UT
mgaido91 2bc5cb4
review comment
mgaido91 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 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 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 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 |
---|---|---|
|
@@ -216,8 +216,6 @@ class BucketizerSuite extends SparkFunSuite with MLlibTestSparkContext with Defa | |
.setOutputCols(Array("result1", "result2")) | ||
.setSplitsArray(splits) | ||
|
||
assert(bucketizer1.isBucketizeMultipleColumns()) | ||
|
||
bucketizer1.transform(dataFrame).select("result1", "expected1", "result2", "expected2") | ||
BucketizerSuite.checkBucketResults(bucketizer1.transform(dataFrame), | ||
Seq("result1", "result2"), | ||
|
@@ -233,8 +231,6 @@ class BucketizerSuite extends SparkFunSuite with MLlibTestSparkContext with Defa | |
.setOutputCols(Array("result")) | ||
.setSplitsArray(Array(splits(0))) | ||
|
||
assert(bucketizer2.isBucketizeMultipleColumns()) | ||
|
||
withClue("Invalid feature value -0.9 was not caught as an invalid feature!") { | ||
intercept[SparkException] { | ||
bucketizer2.transform(badDF1).collect() | ||
|
@@ -268,8 +264,6 @@ class BucketizerSuite extends SparkFunSuite with MLlibTestSparkContext with Defa | |
.setOutputCols(Array("result1", "result2")) | ||
.setSplitsArray(splits) | ||
|
||
assert(bucketizer.isBucketizeMultipleColumns()) | ||
|
||
BucketizerSuite.checkBucketResults(bucketizer.transform(dataFrame), | ||
Seq("result1", "result2"), | ||
Seq("expected1", "expected2")) | ||
|
@@ -295,8 +289,6 @@ class BucketizerSuite extends SparkFunSuite with MLlibTestSparkContext with Defa | |
.setOutputCols(Array("result1", "result2")) | ||
.setSplitsArray(splits) | ||
|
||
assert(bucketizer.isBucketizeMultipleColumns()) | ||
|
||
bucketizer.setHandleInvalid("keep") | ||
BucketizerSuite.checkBucketResults(bucketizer.transform(dataFrame), | ||
Seq("result1", "result2"), | ||
|
@@ -335,7 +327,6 @@ class BucketizerSuite extends SparkFunSuite with MLlibTestSparkContext with Defa | |
.setInputCols(Array("myInputCol")) | ||
.setOutputCols(Array("myOutputCol")) | ||
.setSplitsArray(Array(Array(0.1, 0.8, 0.9))) | ||
assert(t.isBucketizeMultipleColumns()) | ||
testDefaultReadWrite(t) | ||
} | ||
|
||
|
@@ -348,8 +339,6 @@ class BucketizerSuite extends SparkFunSuite with MLlibTestSparkContext with Defa | |
.setOutputCols(Array("result1", "result2")) | ||
.setSplitsArray(Array(Array(-0.5, 0.0, 0.5), Array(-0.5, 0.0, 0.5))) | ||
|
||
assert(bucket.isBucketizeMultipleColumns()) | ||
|
||
val pl = new Pipeline() | ||
.setStages(Array(bucket)) | ||
.fit(df) | ||
|
@@ -401,15 +390,27 @@ class BucketizerSuite extends SparkFunSuite with MLlibTestSparkContext with Defa | |
} | ||
} | ||
|
||
test("Both inputCol and inputCols are set") { | ||
val bucket = new Bucketizer() | ||
.setInputCol("feature1") | ||
.setOutputCol("result") | ||
.setSplits(Array(-0.5, 0.0, 0.5)) | ||
.setInputCols(Array("feature1", "feature2")) | ||
|
||
// When both are set, we ignore `inputCols` and just map the column specified by `inputCol`. | ||
assert(bucket.isBucketizeMultipleColumns() == false) | ||
test("assert exception is thrown if both multi-column and single-column params are set") { | ||
val df = Seq((0.5, 0.3), (0.5, -0.4)).toDF("feature1", "feature2") | ||
ParamsSuite.testExclusiveParams(new Bucketizer, df, ("inputCol", "feature1"), | ||
("inputCols", Array("feature1", "feature2"))) | ||
ParamsSuite.testExclusiveParams(new Bucketizer, df, ("inputCol", "feature1"), | ||
("outputCol", "result1"), ("splits", Array(-0.5, 0.0, 0.5)), | ||
("outputCols", Array("result1", "result2"))) | ||
ParamsSuite.testExclusiveParams(new Bucketizer, df, ("inputCol", "feature1"), | ||
("outputCol", "result1"), ("splits", Array(-0.5, 0.0, 0.5)), | ||
("splitsArray", Array(Array(-0.5, 0.0, 0.5), Array(-0.5, 0.0, 0.5)))) | ||
|
||
// this should fail because at least one of inputCol and inputCols must be set | ||
ParamsSuite.testExclusiveParams(new Bucketizer, df, ("outputCol", "feature1"), | ||
("splits", Array(-0.5, 0.0, 0.5))) | ||
|
||
// the following should fail because not all the params are set | ||
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. Technically here we should probably also test the |
||
ParamsSuite.testExclusiveParams(new Bucketizer, df, ("inputCol", "feature1"), | ||
("outputCol", "result1")) | ||
ParamsSuite.testExclusiveParams(new Bucketizer, df, | ||
("inputCols", Array("feature1", "feature2")), | ||
("outputCols", Array("result1", "result2"))) | ||
} | ||
} | ||
|
||
|
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
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.
We should also test the other exclusive params (input cols and splits params) as per https://github.com/apache/spark/pull/19993/files#r159133936