XGBoost doesn't generate as many tree as specified in the num_round parameter

Viewed 491

This is not a bug but a question to understand. When I call getModelDump from the Booster object, I don't get as many trees as I have in "num_round" parameter. I was thinking if "num_round" is 100 then, XGBoost will generate 100 trees sequentially and I will see all these trees when I call getModelDump. I am sure there is a logical reason behind or my knowledge is wrong. Could you please explain this situation?

val paramMap = List(
      "eta" -> 0.1, "max_depth" -> 7, "objective" -> "binary:logistic", "num_round" ->100,
      "eval_metric" -> "auc", "nworkers" -> 8).toMap
    val xgboostEstimator = new XGBoostEstimator(paramMap)
//TrainModel is another set of standard Spark features like StringIndexer, OnehotEncoding and VectorAssembler
    val pipelineXGBoost = new Pipeline().setStages(Array(trainModel, xgboostEstimator))
    val cvModel = pipelineXGBoost.fit(train)
//Below call generates only 2 tree instead of 100 as num_round is 100!!!
    println(cvModel.stages(1).asInstanceOf[XGBoostClassificationModel].booster.getModelDump()(0))

Github link to the question https://github.com/dmlc/xgboost/issues/2610

Versions are as below using scala 2.11

  "ml.dmlc" % "xgboost4j" % "0.7",
  "ml.dmlc" % "xgboost4j-spark" % "0.7",
  "org.apache.spark" %% "spark-core" % "2.2.0",
  "org.apache.spark" %% "spark-sql" % "2.2.0",
  "org.apache.spark" %% "spark-graphx" % "2.2.0",
  "org.apache.spark" %% "spark-mllib" % "2.2.0",
1 Answers
Related