Skip to content

Commit

Permalink
change gpu side
Browse files Browse the repository at this point in the history
  • Loading branch information
tubihongfeili committed May 15, 2024
1 parent 1b20b25 commit c3ed781
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import ml.dmlc.xgboost4j.scala.spark.{XGBoostRegressionModel, XGBoostRegressor}
import org.apache.spark.ml.feature.VectorAssembler
import org.apache.spark.sql.functions.{col, udf}
import org.apache.spark.sql.types.{FloatType, IntegerType, StructField, StructType}
import org.apache.commons.logging.LogFactory

class GpuXGBoostRegressorSuite extends GpuTestSuite {
val logger = LogFactory.getLog("XGBoostSpark")

val labelName = "label_col"
val groupName = "group_col"
Expand Down Expand Up @@ -255,4 +257,22 @@ class GpuXGBoostRegressorSuite extends GpuTestSuite {
assert(testDf.count() === ret.length)
}
}

test("Ranking: test position bias") {
withGpuSparkSession(enableCsvConf()) { spark =>
logger.info("hongfeili-scala: begin execute test")
val xgbParam = Map("eta" -> 0.1f, "max_depth" -> 2, "objective" -> "rank:ndcg",
"num_round" -> 10, "num_workers" -> 1, "tree_method" -> "gpu_hist",
"features_cols" -> featureNames, "label_col" -> labelName, "lambdarank_unbiased" -> true, "eval_metric" -> "ndcg")
val Array(trainingDf, testDf) = spark.read.option("header", "true").schema(schema)
.csv(getResourcePath("/rank.train.csv")).randomSplit(Array(0.7, 0.3), seed = 1)

val model = new XGBoostRegressor(xgbParam)
.setGroupCol(groupName)
.fit(trainingDf)

val ret = model.transform(testDf).collect()
assert(testDf.count() === ret.length)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import org.apache.spark.sql.{DataFrame, Row}
import org.scalatest.funsuite.AnyFunSuite

import org.apache.spark.ml.feature.VectorAssembler
import org.apache.commons.logging.LogFactory


class XGBoostRegressorSuite extends AnyFunSuite with PerTest with TmpFolderPerSuite {
protected val treeMethod: String = "auto"
val logger = LogFactory.getLog("XGBoostSpark")

test("XGBoost-Spark XGBoostRegressor output should match XGBoost4j") {
val trainingDM = new DMatrix(Regression.train.iterator)
Expand Down Expand Up @@ -133,6 +136,7 @@ class XGBoostRegressorSuite extends AnyFunSuite with PerTest with TmpFolderPerSu
}

test("ranking: test position bias") {
logger.info("hongfeili-scala: begin execute test")
val paramMap = Map("eta" -> "1", "max_depth" -> "6", "silent" -> "0", "verbosity" -> "3",
"objective" -> "rank:ndcg", "num_workers" -> numWorkers, "num_round" -> 5,
"group_col" -> "group", "tree_method" -> treeMethod, "lambdarank_unbiased" -> true, "eval_metric" -> "ndcg")
Expand All @@ -142,7 +146,6 @@ class XGBoostRegressorSuite extends AnyFunSuite with PerTest with TmpFolderPerSu
val model = new XGBoostRegressor(paramMap).fit(trainingDF)

val prediction = model.transform(testDF).collect()
println("hello---------hongfei")
assert(testDF.count() === prediction.length)
}

Expand Down

0 comments on commit c3ed781

Please sign in to comment.