[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:
Shaochen Shi 2020-08-02 08:16:42 +08:00 committed by GitHub
parent 5a2dcd1c33
commit 71197d1dfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 2 deletions

View File

@ -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
)

View File

@ -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
)

View File

@ -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)
}
}
}