[jvm-packages] Add methods operating attributes of booster in jvm package, which follow API design in python package. (#4336)

This commit is contained in:
Xu Xiao
2019-04-09 02:00:35 +08:00
committed by Nan Zhu
parent 9080bba815
commit 60a9af567c
6 changed files with 197 additions and 0 deletions

View File

@@ -32,6 +32,48 @@ import scala.collection.mutable
class Booster private[xgboost4j](private[xgboost4j] var booster: JBooster)
extends Serializable with KryoSerializable {
/**
* Get attributes stored in the Booster as a Map.
*
* @return A map contain attribute pairs.
*/
@throws(classOf[XGBoostError])
def getAttrs: Map[String, String] = {
booster.getAttrs.asScala.toMap
}
/**
* Get attribute from the Booster.
*
* @param key attr name
* @return attr value
*/
@throws(classOf[XGBoostError])
def getAttr(key: String): String = {
booster.getAttr(key)
}
/**
* Set attribute to the Booster.
*
* @param key attr name
* @param value attr value
*/
@throws(classOf[XGBoostError])
def setAttr(key: String, value: String): Unit = {
booster.setAttr(key, value)
}
/**
* set attributes
*
* @param params attributes key-value map
*/
@throws(classOf[XGBoostError])
def setAttrs(params: Map[String, String]): Unit = {
booster.setAttrs(params.asJava)
}
/**
* Set parameter to the Booster.
*