Skip to content

Commit

Permalink
Expose setCustomObj & setCustomEval for XGBoostClassifier & XGBoostRe…
Browse files Browse the repository at this point in the history
…gressor. (dmlc#3486)
  • Loading branch information
yanboliang authored and CodingCat committed Jul 18, 2018
1 parent b6dcbf0 commit c004cea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import scala.collection.mutable

import ml.dmlc.xgboost4j.java.Rabit
import ml.dmlc.xgboost4j.scala.{Booster, DMatrix, XGBoost => SXGBoost}
import ml.dmlc.xgboost4j.scala.{EvalTrait, ObjectiveTrait}
import ml.dmlc.xgboost4j.scala.spark.params._
import ml.dmlc.xgboost4j.{LabeledPoint => XGBLabeledPoint}

Expand Down Expand Up @@ -134,6 +135,10 @@ class XGBoostClassifier (

def setNumEarlyStoppingRounds(value: Int): this.type = set(numEarlyStoppingRounds, value)

def setCustomObj(value: ObjectiveTrait): this.type = set(customObj, value)

def setCustomEval(value: EvalTrait): this.type = set(customEval, value)

// called at the start of fit/train when 'eval_metric' is not defined
private def setupDefaultEvalMetric(): String = {
require(isDefined(objective), "Users must set \'objective\' via xgboostParams.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ml.dmlc.xgboost4j.java.Rabit
import ml.dmlc.xgboost4j.{LabeledPoint => XGBLabeledPoint}
import ml.dmlc.xgboost4j.scala.spark.params.{DefaultXGBoostParamsReader, _}
import ml.dmlc.xgboost4j.scala.{Booster, DMatrix, XGBoost => SXGBoost}
import ml.dmlc.xgboost4j.scala.{EvalTrait, ObjectiveTrait}

import org.apache.hadoop.fs.Path
import org.apache.spark.TaskContext
Expand Down Expand Up @@ -136,6 +137,10 @@ class XGBoostRegressor (

def setNumEarlyStoppingRounds(value: Int): this.type = set(numEarlyStoppingRounds, value)

def setCustomObj(value: ObjectiveTrait): this.type = set(customObj, value)

def setCustomEval(value: EvalTrait): this.type = set(customEval, value)

// called at the start of fit/train when 'eval_metric' is not defined
private def setupDefaultEvalMetric(): String = {
require(isDefined(objective), "Users must set \'objective\' via xgboostParams.")
Expand Down

0 comments on commit c004cea

Please sign in to comment.