[jvm-packages] Fix wrong method name setAllowZeroForMissingValue. (#5740)
* Allow non-zero for missing value when training. * Fix wrong method names. * Add a unit test * Move the getter/setter unit test to MissingValueHandlingSuite Co-authored-by: Hyunsu Cho <chohyu01@cs.washington.edu>
This commit is contained in:
parent
5a2dcd1c33
commit
71197d1dfa
@ -141,6 +141,11 @@ class XGBoostClassifier (
|
||||
|
||||
def setCustomEval(value: EvalTrait): this.type = set(customEval, value)
|
||||
|
||||
def setAllowNonZeroForMissing(value: Boolean): this.type = set(
|
||||
allowNonZeroForMissing,
|
||||
value
|
||||
)
|
||||
|
||||
def setSinglePrecisionHistogram(value: Boolean): this.type =
|
||||
set(singlePrecisionHistogram, value)
|
||||
|
||||
@ -248,7 +253,7 @@ class XGBoostClassificationModel private[ml](
|
||||
|
||||
def setMissing(value: Float): this.type = set(missing, value)
|
||||
|
||||
def setAllowZeroForMissingValue(value: Boolean): this.type = set(
|
||||
def setAllowNonZeroForMissing(value: Boolean): this.type = set(
|
||||
allowNonZeroForMissing,
|
||||
value
|
||||
)
|
||||
|
||||
@ -145,6 +145,11 @@ class XGBoostRegressor (
|
||||
|
||||
def setCustomEval(value: EvalTrait): this.type = set(customEval, value)
|
||||
|
||||
def setAllowNonZeroForMissing(value: Boolean): this.type = set(
|
||||
allowNonZeroForMissing,
|
||||
value
|
||||
)
|
||||
|
||||
def setSinglePrecisionHistogram(value: Boolean): this.type =
|
||||
set(singlePrecisionHistogram, value)
|
||||
|
||||
@ -244,7 +249,7 @@ class XGBoostRegressionModel private[ml] (
|
||||
|
||||
def setMissing(value: Float): this.type = set(missing, value)
|
||||
|
||||
def setAllowZeroForMissingValue(value: Boolean): this.type = set(
|
||||
def setAllowNonZeroForMissing(value: Boolean): this.type = set(
|
||||
allowNonZeroForMissing,
|
||||
value
|
||||
)
|
||||
|
||||
@ -198,4 +198,38 @@ class MissingValueHandlingSuite extends FunSuite with PerTest {
|
||||
val model = new XGBoostClassifier(paramMap).fit(inputDF)
|
||||
model.transform(inputDF).collect()
|
||||
}
|
||||
|
||||
test("Getter and setter for AllowNonZeroForMissingValue works") {
|
||||
{
|
||||
val paramMap = Map("eta" -> "1", "max_depth" -> "6",
|
||||
"objective" -> "binary:logistic", "num_round" -> 5, "num_workers" -> numWorkers)
|
||||
val training = buildDataFrame(Classification.train)
|
||||
val classifier = new XGBoostClassifier(paramMap)
|
||||
classifier.setAllowNonZeroForMissing(true)
|
||||
assert(classifier.getAllowNonZeroForMissingValue)
|
||||
classifier.setAllowNonZeroForMissing(false)
|
||||
assert(!classifier.getAllowNonZeroForMissingValue)
|
||||
val model = classifier.fit(training)
|
||||
model.setAllowNonZeroForMissing(true)
|
||||
assert(model.getAllowNonZeroForMissingValue)
|
||||
model.setAllowNonZeroForMissing(false)
|
||||
assert(!model.getAllowNonZeroForMissingValue)
|
||||
}
|
||||
|
||||
{
|
||||
val paramMap = Map("eta" -> "1", "max_depth" -> "6", "silent" -> "1",
|
||||
"objective" -> "reg:squarederror", "num_round" -> 5, "num_workers" -> numWorkers)
|
||||
val training = buildDataFrame(Regression.train)
|
||||
val regressor = new XGBoostRegressor(paramMap)
|
||||
regressor.setAllowNonZeroForMissing(true)
|
||||
assert(regressor.getAllowNonZeroForMissingValue)
|
||||
regressor.setAllowNonZeroForMissing(false)
|
||||
assert(!regressor.getAllowNonZeroForMissingValue)
|
||||
val model = regressor.fit(training)
|
||||
model.setAllowNonZeroForMissing(true)
|
||||
assert(model.getAllowNonZeroForMissingValue)
|
||||
model.setAllowNonZeroForMissing(false)
|
||||
assert(!model.getAllowNonZeroForMissingValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user