-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23265][ML]Update multi-column error handling logic in QuantileDiscretizer #20442
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
Changes from all commits
106f8cf
d22093b
9674c3c
f68940b
db35f61
73aeb1c
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 |
|---|---|---|
|
|
@@ -171,25 +171,38 @@ final class QuantileDiscretizer @Since("1.6.0") (@Since("1.6.0") override val ui | |
| @Since("2.3.0") | ||
| def setOutputCols(value: Array[String]): this.type = set(outputCols, value) | ||
|
|
||
| private[feature] def getInOutCols: (Array[String], Array[String]) = { | ||
| require((isSet(inputCol) && isSet(outputCol) && !isSet(inputCols) && !isSet(outputCols)) || | ||
| (!isSet(inputCol) && !isSet(outputCol) && isSet(inputCols) && isSet(outputCols)), | ||
| "QuantileDiscretizer only supports setting either inputCol/outputCol or" + | ||
| "inputCols/outputCols." | ||
| ) | ||
| @Since("1.6.0") | ||
| override def transformSchema(schema: StructType): StructType = { | ||
| ParamValidators.checkSingleVsMultiColumnParams(this, Seq(outputCol), | ||
|
Member
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.
If we want
Contributor
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. Thanks @viirya for your quick reply! is that we can actually setNumBuckets for multi columns. I looked the previous conversion, we have decided to allow setNumBuckets for multi columns. In the multi columns case
Member
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. ah, I see. thanks! |
||
| Seq(outputCols)) | ||
|
|
||
| if (isSet(inputCol)) { | ||
| (Array($(inputCol)), Array($(outputCol))) | ||
| } else { | ||
| require($(inputCols).length == $(outputCols).length, | ||
| "inputCols number do not match outputCols") | ||
| ($(inputCols), $(outputCols)) | ||
| require(!isSet(numBucketsArray), | ||
| s"numBucketsArray can't be set for single-column QuantileDiscretizer.") | ||
|
||
| } | ||
| } | ||
|
|
||
| @Since("1.6.0") | ||
| override def transformSchema(schema: StructType): StructType = { | ||
| val (inputColNames, outputColNames) = getInOutCols | ||
| if (isSet(inputCols)) { | ||
| require(getInputCols.length == getOutputCols.length, | ||
| s"QuantileDiscretizer $this has mismatched Params " + | ||
| s"for multi-column transform. Params (inputCols, outputCols) should have " + | ||
| s"equal lengths, but they have different lengths: " + | ||
| s"(${getInputCols.length}, ${getOutputCols.length}).") | ||
| if (isSet(numBucketsArray)) { | ||
| require(getInputCols.length == getNumBucketsArray.length, | ||
| s"QuantileDiscretizer $this has mismatched Params " + | ||
| s"for multi-column transform. Params (inputCols, outputCols, numBucketsArray) " + | ||
| s"should have equal lengths, but they have different lengths: " + | ||
| s"(${getInputCols.length}, ${getOutputCols.length}, ${getNumBucketsArray.length}).") | ||
| require(!isSet(numBuckets), | ||
| s"exactly one of numBuckets, numBucketsArray Params to be set, but both are set." ) | ||
| } | ||
| } | ||
|
|
||
| val (inputColNames, outputColNames) = if (isSet(inputCols)) { | ||
| ($(inputCols).toSeq, $(outputCols).toSeq) | ||
| } else { | ||
| (Seq($(inputCol)), Seq($(outputCol))) | ||
| } | ||
| val existingFields = schema.fields | ||
| var outputFields = existingFields | ||
| inputColNames.zip(outputColNames).foreach { case (inputColName, outputColName) => | ||
|
|
||
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.
Setting
numBucketsArraywhen single-column can be an error. SincecheckSingleVsMultiColumnParamsdoesn't support this usage, I think we may need to check it here.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.
Thanks for your comment. I will add the check.