class LightGBMBooster extends Serializable
Represents a LightGBM Booster learner
- Annotations
- @SerialVersionUID()
- Alphabetic
- By Inheritance
- LightGBMBooster
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
LightGBMBooster(model: String)
Represents a LightGBM Booster learner
Represents a LightGBM Booster learner
- model
The string serialized representation of the learner
-
new
LightGBMBooster(trainDataset: LightGBMDataset, parameters: String)
Represents a LightGBM Booster learner
Represents a LightGBM Booster learner
- trainDataset
The training dataset
- parameters
The booster initialization parameters
-
new
LightGBMBooster(trainDataset: Option[LightGBMDataset] = None, parameters: Option[String] = None, modelStr: Option[String] = None)
- trainDataset
The training dataset
- parameters
The booster initialization parameters
- modelStr
Optional parameter with the string serialized representation of the learner
Value Members
-
def
addValidationDataset(dataset: LightGBMDataset): Unit
Adds the specified LightGBMDataset to be the validation dataset.
Adds the specified LightGBMDataset to be the validation dataset.
- dataset
The LightGBMDataset to add as the validation dataset.
- var bestIteration: Int
-
lazy val
boosterHandler: BoosterHandler
- Annotations
- @transient()
-
def
dumpModel(session: SparkSession, filename: String, overwrite: Boolean): Unit
Dumps the native model pointer to file.
Dumps the native model pointer to file.
- session
The spark session
- filename
The name of the file to save the model to
- overwrite
Whether to overwrite if the file already exists
- def featuresShap(features: Vector): Array[Double]
-
def
freeNativeMemory(): Unit
Frees any native memory held by the underlying booster pointer.
-
def
getEvalNames: Array[String]
Get the evaluation dataset column names from the native booster.
Get the evaluation dataset column names from the native booster.
- returns
The evaluation dataset column names.
-
def
getEvalResults(evalNames: Array[String], dataIndex: Int): Array[(String, Double)]
Get the evaluation for the training data and validation data.
Get the evaluation for the training data and validation data.
- evalNames
The names of the evaluation metrics.
- dataIndex
Index of data, 0: training data, 1: 1st validation data, 2: 2nd validation data and so on.
- returns
Array of tuples containing the evaluation metric name and metric value.
-
def
getFeatureImportances(importanceType: String): Array[Double]
Calls into LightGBM to retrieve the feature importances.
Calls into LightGBM to retrieve the feature importances.
- importanceType
Can be "split" or "gain"
- returns
The feature importance values as an array.
-
def
getNativeModel(): String
Gets the native model serialized representation as a string.
-
def
innerPredict(dataIndex: Int, classification: Boolean): Array[Array[Double]]
Get predictions for the training and evaluation data on the booster.
Get predictions for the training and evaluation data on the booster.
- dataIndex
Index of data, 0: training data, 1: 1st validation data, 2: 2nd validation data and so on.
- classification
Whether this is a classification scenario or not.
- returns
The predictions as a 2D array where first level is for row index and second level is optional if there are classes.
-
def
mergeBooster(model: String): Unit
Merges this Booster with the specified model.
Merges this Booster with the specified model.
- model
The string serialized representation of the learner to merge.
- val modelStr: Option[String]
- lazy val numClasses: Int
- lazy val numFeatures: Int
- lazy val numModelPerIteration: Int
- lazy val numTotalIterations: Int
- lazy val numTotalModel: Int
- val parameters: Option[String]
- def predictLeaf(features: Vector): Array[Double]
-
def
resetParameter(newParameters: String): Unit
Reset the specified parameters on the native booster.
Reset the specified parameters on the native booster.
- newParameters
The new parameters to set.
-
def
saveNativeModel(session: SparkSession, filename: String, overwrite: Boolean): Unit
Saves the native model serialized representation to file.
Saves the native model serialized representation to file.
- session
The spark session
- filename
The name of the file to save the model to
- overwrite
Whether to overwrite if the file already exists
-
def
saveToString(upToIteration: Option[Int] = None): String
Saves the booster to string representation.
Saves the booster to string representation.
- upToIteration
The zero-based index of the iteration to save as the last one (ignoring the rest).
- returns
The serialized string representation of the Booster.
- def score(features: Vector, raw: Boolean, classification: Boolean, disableShapeCheck: Boolean): Array[Double]
-
def
setBestIteration(bestIteration: Int): Unit
Sets the best iteration and also the numIterations to be the best iteration.
Sets the best iteration and also the numIterations to be the best iteration.
- bestIteration
The best iteration computed by early stopping.
-
def
setNumIterations(numIterations: Int): Unit
Sets the total number of iterations used in the prediction.
Sets the total number of iterations used in the prediction. If <= 0, all iterations from
are used (no limits).start_iteration
- numIterations
The total number of iterations used in the prediction.
-
def
setStartIteration(startIteration: Int): Unit
Sets the start index of the iteration to predict.
Sets the start index of the iteration to predict. If <= 0, starts from the first iteration.
- startIteration
The start index of the iteration to predict.
- val trainDataset: Option[LightGBMDataset]
-
def
updateOneIteration(): Boolean
Updates the booster for one iteration.
Updates the booster for one iteration.
- returns
True if terminated training early.
-
def
updateOneIterationCustom(gradient: Array[Float], hessian: Array[Float]): Boolean
Updates the booster with custom loss function for one iteration.
Updates the booster with custom loss function for one iteration.
- gradient
The gradient from custom loss function.
- hessian
The hessian matrix from custom loss function.
- returns
True if terminated training early.