[jvm-packages] unify setFeaturesCol API for XGBoostRegressor (#7784)
This commit is contained in:
parent
e5ab8f3ebe
commit
2454407f3a
@ -112,7 +112,7 @@ private[spark] object GpuUtils {
|
|||||||
val msg = if (fitting) "train" else "transform"
|
val msg = if (fitting) "train" else "transform"
|
||||||
// feature columns
|
// feature columns
|
||||||
require(featureNames.nonEmpty, s"Gpu $msg requires features columns. " +
|
require(featureNames.nonEmpty, s"Gpu $msg requires features columns. " +
|
||||||
"please refer to setFeaturesCols!")
|
"please refer to `setFeaturesCol(value: Array[String])`!")
|
||||||
featureNames.foreach(fn => checkNumericType(schema, fn))
|
featureNames.foreach(fn => checkNumericType(schema, fn))
|
||||||
if (fitting) {
|
if (fitting) {
|
||||||
require(labelName.nonEmpty, "label column is not set.")
|
require(labelName.nonEmpty, "label column is not set.")
|
||||||
|
|||||||
@ -147,12 +147,13 @@ class GpuXGBoostClassifierSuite extends GpuTestSuite {
|
|||||||
.csv(dataPath).randomSplit(Array(0.7, 0.3), seed = 1)
|
.csv(dataPath).randomSplit(Array(0.7, 0.3), seed = 1)
|
||||||
|
|
||||||
// Since CPU model does not know the information about the features cols that GPU transform
|
// Since CPU model does not know the information about the features cols that GPU transform
|
||||||
// pipeline requires. End user needs to setFeaturesCols in the model manually
|
// pipeline requires. End user needs to setFeaturesCol(features: Array[String]) in the model
|
||||||
|
// manually
|
||||||
val thrown = intercept[IllegalArgumentException](cpuModel
|
val thrown = intercept[IllegalArgumentException](cpuModel
|
||||||
.transform(testDf)
|
.transform(testDf)
|
||||||
.collect())
|
.collect())
|
||||||
assert(thrown.getMessage.contains("Gpu transform requires features columns. " +
|
assert(thrown.getMessage.contains("Gpu transform requires features columns. " +
|
||||||
"please refer to setFeaturesCols"))
|
"please refer to `setFeaturesCol(value: Array[String])`"))
|
||||||
|
|
||||||
val left = cpuModel
|
val left = cpuModel
|
||||||
.setFeaturesCol(featureNames)
|
.setFeaturesCol(featureNames)
|
||||||
|
|||||||
@ -86,7 +86,7 @@ class GpuXGBoostRegressorSuite extends GpuTestSuite {
|
|||||||
.csv(getResourcePath("/rank.train.csv")).randomSplit(Array(0.7, 0.3), seed = 1)
|
.csv(getResourcePath("/rank.train.csv")).randomSplit(Array(0.7, 0.3), seed = 1)
|
||||||
|
|
||||||
val classifier = new XGBoostRegressor(xgbParam)
|
val classifier = new XGBoostRegressor(xgbParam)
|
||||||
.setFeaturesCols(featureNames)
|
.setFeaturesCol(featureNames)
|
||||||
.setLabelCol(labelName)
|
.setLabelCol(labelName)
|
||||||
.setTreeMethod("gpu_hist")
|
.setTreeMethod("gpu_hist")
|
||||||
(classifier.fit(rawInput), testDf)
|
(classifier.fit(rawInput), testDf)
|
||||||
@ -143,20 +143,21 @@ class GpuXGBoostRegressorSuite extends GpuTestSuite {
|
|||||||
.csv(getResourcePath("/rank.train.csv")).randomSplit(Array(0.7, 0.3), seed = 1)
|
.csv(getResourcePath("/rank.train.csv")).randomSplit(Array(0.7, 0.3), seed = 1)
|
||||||
|
|
||||||
// Since CPU model does not know the information about the features cols that GPU transform
|
// Since CPU model does not know the information about the features cols that GPU transform
|
||||||
// pipeline requires. End user needs to setFeaturesCols in the model manually
|
// pipeline requires. End user needs to setFeaturesCol(features: Array[String]) in the model
|
||||||
|
// manually
|
||||||
val thrown = intercept[IllegalArgumentException](cpuModel
|
val thrown = intercept[IllegalArgumentException](cpuModel
|
||||||
.transform(testDf)
|
.transform(testDf)
|
||||||
.collect())
|
.collect())
|
||||||
assert(thrown.getMessage.contains("Gpu transform requires features columns. " +
|
assert(thrown.getMessage.contains("Gpu transform requires features columns. " +
|
||||||
"please refer to setFeaturesCols"))
|
"please refer to `setFeaturesCol(value: Array[String])`"))
|
||||||
|
|
||||||
val left = cpuModel
|
val left = cpuModel
|
||||||
.setFeaturesCols(featureNames)
|
.setFeaturesCol(featureNames)
|
||||||
.transform(testDf)
|
.transform(testDf)
|
||||||
.collect()
|
.collect()
|
||||||
|
|
||||||
val right = cpuModelFromFile
|
val right = cpuModelFromFile
|
||||||
.setFeaturesCols(featureNames)
|
.setFeaturesCol(featureNames)
|
||||||
.transform(testDf)
|
.transform(testDf)
|
||||||
.collect()
|
.collect()
|
||||||
|
|
||||||
@ -173,7 +174,7 @@ class GpuXGBoostRegressorSuite extends GpuTestSuite {
|
|||||||
.csv(getResourcePath("/rank.train.csv")).randomSplit(Array(0.7, 0.3), seed = 1)
|
.csv(getResourcePath("/rank.train.csv")).randomSplit(Array(0.7, 0.3), seed = 1)
|
||||||
|
|
||||||
val classifier = new XGBoostRegressor(xgbParam)
|
val classifier = new XGBoostRegressor(xgbParam)
|
||||||
.setFeaturesCols(featureNames)
|
.setFeaturesCol(featureNames)
|
||||||
.setLabelCol(labelName)
|
.setLabelCol(labelName)
|
||||||
.setTreeMethod("gpu_hist")
|
.setTreeMethod("gpu_hist")
|
||||||
classifier.fit(rawInput)
|
classifier.fit(rawInput)
|
||||||
|
|||||||
@ -150,7 +150,7 @@ class XGBoostRegressor (
|
|||||||
* This API is only used in GPU train pipeline of xgboost4j-spark-gpu, which requires
|
* This API is only used in GPU train pipeline of xgboost4j-spark-gpu, which requires
|
||||||
* all feature columns must be numeric types.
|
* all feature columns must be numeric types.
|
||||||
*/
|
*/
|
||||||
def setFeaturesCols(value: Array[String]): this.type =
|
def setFeaturesCol(value: Array[String]): this.type =
|
||||||
set(featuresCols, value)
|
set(featuresCols, value)
|
||||||
|
|
||||||
// called at the start of fit/train when 'eval_metric' is not defined
|
// called at the start of fit/train when 'eval_metric' is not defined
|
||||||
@ -257,7 +257,7 @@ class XGBoostRegressionModel private[ml] (
|
|||||||
* This API is only used in GPU train pipeline of xgboost4j-spark-gpu, which requires
|
* This API is only used in GPU train pipeline of xgboost4j-spark-gpu, which requires
|
||||||
* all feature columns must be numeric types.
|
* all feature columns must be numeric types.
|
||||||
*/
|
*/
|
||||||
def setFeaturesCols(value: Array[String]): this.type =
|
def setFeaturesCol(value: Array[String]): this.type =
|
||||||
set(featuresCols, value)
|
set(featuresCols, value)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user