public class Booster extends Object implements Serializable, com.esotericsoftware.kryo.KryoSerializable
Modifier and Type | Class and Description |
---|---|
static class |
Booster.FeatureImportanceType
Supported feature importance types
WEIGHT = Number of nodes that a feature was used to determine a split
GAIN = Average information gain per split for a feature
COVER = Average cover per split for a feature
TOTAL_GAIN = Total information gain over all splits of a feature
TOTAL_COVER = Total cover over all splits of a feature
|
static class |
Booster.PredictionType
Type of prediction, used for inplace_predict.
|
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_FORMAT |
Modifier and Type | Method and Description |
---|---|
void |
boost(DMatrix dtrain,
float[] grad,
float[] hess)
Deprecated.
|
void |
boost(DMatrix dtrain,
int iter,
float[] grad,
float[] hess)
Update with give grad and hess
|
void |
dispose() |
String |
evalSet(DMatrix[] evalMatrixs,
String[] evalNames,
IEvaluation eval)
evaluate with given customized Evaluation class
|
String |
evalSet(DMatrix[] evalMatrixs,
String[] evalNames,
IEvaluation eval,
float[] metricsOut) |
String |
evalSet(DMatrix[] evalMatrixs,
String[] evalNames,
int iter)
evaluate with given dmatrixs.
|
String |
evalSet(DMatrix[] evalMatrixs,
String[] evalNames,
int iter,
float[] metricsOut)
evaluate with given dmatrixs.
|
protected void |
finalize() |
String |
getAttr(String key)
Get attribute from the Booster.
|
Map<String,String> |
getAttrs()
Get attributes stored in the Booster as a Map.
|
String[] |
getFeatureNames()
Get feature names from the Booster.
|
Map<String,Integer> |
getFeatureScore(String featureMap)
Get importance of each feature
|
Map<String,Integer> |
getFeatureScore(String[] featureNames)
Get importance of each feature with specified feature names.
|
String[] |
getFeatureTypes()
Get feature types from the Booster.
|
String[] |
getModelDump(String[] featureNames,
boolean withStats)
Get the dump of the model as a string array with specified feature names.
|
String[] |
getModelDump(String[] featureNames,
boolean withStats,
String format) |
String[] |
getModelDump(String featureMap,
boolean withStats)
Get the dump of the model as a string array
|
String[] |
getModelDump(String featureMap,
boolean withStats,
String format) |
int |
getNumBoostedRound() |
long |
getNumFeature()
Get number of model features.
|
Map<String,Double> |
getScore(String[] featureNames,
String importanceType)
Get the feature importances for gain or cover (average or total)
|
Map<String,Double> |
getScore(String featureMap,
String importanceType)
Get the feature importances for gain or cover (average or total), with feature names
|
float[][] |
inplace_predict(float[] data,
int nrow,
int ncol,
float missing)
Perform thread-safe prediction.
|
float[][] |
inplace_predict(float[] data,
int nrow,
int ncol,
float missing,
int[] iteration_range)
Perform thread-safe prediction.
|
float[][] |
inplace_predict(float[] data,
int nrow,
int ncol,
float missing,
int[] iteration_range,
Booster.PredictionType predict_type,
float[] base_margin)
Perform thread-safe prediction.
|
float[][] |
predict(DMatrix data)
Predict with data
|
float[][] |
predict(DMatrix data,
boolean outputMargin)
Predict with data
|
float[][] |
predict(DMatrix data,
boolean outputMargin,
int treeLimit)
Advanced predict function with all the options.
|
float[][] |
predictContrib(DMatrix data,
int treeLimit)
Output feature contributions toward predictions of given data
|
float[][] |
predictLeaf(DMatrix data,
int treeLimit)
Predict leaf indices given the data
|
void |
read(com.esotericsoftware.kryo.Kryo kryo,
com.esotericsoftware.kryo.io.Input input) |
void |
saveModel(OutputStream out)
Save the model to file opened as output stream.
|
void |
saveModel(OutputStream out,
String format)
Save the model to file opened as output stream.
|
void |
saveModel(String modelPath)
Save model to modelPath
|
void |
setAttr(String key,
String value)
Set attribute to the Booster.
|
void |
setAttrs(Map<String,String> attrs)
Set attributes to the Booster.
|
void |
setFeatureNames(String[] featureNames)
Set feature names to the Booster.
|
void |
setFeatureTypes(String[] featureTypes)
Set feature types to the Booster.
|
void |
setParam(String key,
Object value)
Set parameter to the Booster.
|
void |
setParams(Map<String,Object> params)
Set parameters to the Booster.
|
byte[] |
toByteArray()
Save model into raw byte array in the UBJSON ("ubj") format.
|
byte[] |
toByteArray(String format)
Save model into raw byte array.
|
void |
update(DMatrix dtrain,
int iter)
Update the booster for one iteration.
|
void |
update(DMatrix dtrain,
int iter,
IObjective obj)
Update with customize obj func
|
void |
update(DMatrix dtrain,
IObjective obj)
Deprecated.
|
void |
write(com.esotericsoftware.kryo.Kryo kryo,
com.esotericsoftware.kryo.io.Output output) |
public static final String DEFAULT_FORMAT
public final void setParam(String key, Object value) throws XGBoostError
key
- param namevalue
- param valueXGBoostError
- native errorpublic void setParams(Map<String,Object> params) throws XGBoostError
params
- parameters key-value mapXGBoostError
- native errorpublic final Map<String,String> getAttrs() throws XGBoostError
XGBoostError
- native errorpublic final String getAttr(String key) throws XGBoostError
key
- attribute keyXGBoostError
- native errorpublic final void setAttr(String key, String value) throws XGBoostError
key
- attribute keyvalue
- attribute valueXGBoostError
- native errorpublic void setAttrs(Map<String,String> attrs) throws XGBoostError
attrs
- attributes key-value mapXGBoostError
- native errorpublic final String[] getFeatureNames() throws XGBoostError
XGBoostError
public void setFeatureNames(String[] featureNames) throws XGBoostError
featureNames
- XGBoostError
public final String[] getFeatureTypes() throws XGBoostError
XGBoostError
public void setFeatureTypes(String[] featureTypes) throws XGBoostError
featureTypes
- XGBoostError
public void update(DMatrix dtrain, int iter) throws XGBoostError
dtrain
- training dataiter
- current iteration numberXGBoostError
- native error@Deprecated public void update(DMatrix dtrain, IObjective obj) throws XGBoostError
XGBoostError
public void update(DMatrix dtrain, int iter, IObjective obj) throws XGBoostError
dtrain
- training dataiter
- The current training iteration.obj
- customized objective classXGBoostError
- native error@Deprecated public void boost(DMatrix dtrain, float[] grad, float[] hess) throws XGBoostError
XGBoostError
public void boost(DMatrix dtrain, int iter, float[] grad, float[] hess) throws XGBoostError
dtrain
- training dataiter
- The current training iteration.grad
- first order of gradienthess
- seconde order of gradientXGBoostError
- native errorpublic String evalSet(DMatrix[] evalMatrixs, String[] evalNames, int iter) throws XGBoostError
evalMatrixs
- dmatrixs for evaluationevalNames
- name for eval dmatrixs, used for check resultsiter
- current eval iterationXGBoostError
- native errorpublic String evalSet(DMatrix[] evalMatrixs, String[] evalNames, int iter, float[] metricsOut) throws XGBoostError
evalMatrixs
- dmatrixs for evaluationevalNames
- name for eval dmatrixs, used for check resultsiter
- current eval iterationmetricsOut
- output array containing the evaluation metrics for each evalMatrixXGBoostError
- native errorpublic String evalSet(DMatrix[] evalMatrixs, String[] evalNames, IEvaluation eval) throws XGBoostError
evalMatrixs
- evaluation matrixevalNames
- evaluation nameseval
- custom evaluatorXGBoostError
- native errorpublic String evalSet(DMatrix[] evalMatrixs, String[] evalNames, IEvaluation eval, float[] metricsOut) throws XGBoostError
XGBoostError
public float[][] inplace_predict(float[] data, int nrow, int ncol, float missing) throws XGBoostError
data
- Flattened input matrix of features for predictionnrow
- The number of preditions to make (count of input matrix rows)ncol
- The number of features in the model (count of input matrix columns)missing
- Value indicating missing element in the data
input matrixXGBoostError
public float[][] inplace_predict(float[] data, int nrow, int ncol, float missing, int[] iteration_range) throws XGBoostError
data
- Flattened input matrix of features for predictionnrow
- The number of preditions to make (count of input matrix rows)ncol
- The number of features in the model (count of input matrix columns)missing
- Value indicating missing element in the data
input matrixiteration_range
- Specifies which layer of trees are used in prediction. For
example, if a random forest is trained with 100 rounds.
Specifying `iteration_range=[10, 20)`, then only the forests
built during [10, 20) (half open set) rounds are used in this
prediction.XGBoostError
public float[][] inplace_predict(float[] data, int nrow, int ncol, float missing, int[] iteration_range, Booster.PredictionType predict_type, float[] base_margin) throws XGBoostError
data
- Flattened input matrix of features for predictionnrow
- The number of preditions to make (count of input matrix rows)ncol
- The number of features in the model (count of input matrix columns)missing
- Value indicating missing element in the data
input matrixiteration_range
- Specifies which layer of trees are used in prediction. For
example, if a random forest is trained with 100 rounds.
Specifying `iteration_range=[10, 20)`, then only the forests
built during [10, 20) (half open set) rounds are used in this
prediction.predict_type
- What kind of prediction to run.XGBoostError
public float[][] predictLeaf(DMatrix data, int treeLimit) throws XGBoostError
data
- The input data.treeLimit
- Number of trees to include, 0 means all trees.XGBoostError
public float[][] predictContrib(DMatrix data, int treeLimit) throws XGBoostError
data
- The input data.treeLimit
- Number of trees to include, 0 means all trees.XGBoostError
public float[][] predict(DMatrix data) throws XGBoostError
data
- dmatrix storing the inputXGBoostError
- native errorpublic float[][] predict(DMatrix data, boolean outputMargin) throws XGBoostError
data
- dataoutputMargin
- output marginXGBoostError
public float[][] predict(DMatrix data, boolean outputMargin, int treeLimit) throws XGBoostError
data
- dataoutputMargin
- output margintreeLimit
- limit number of trees, 0 means all trees.XGBoostError
public void saveModel(String modelPath) throws XGBoostError
modelPath
- model pathXGBoostError
public void saveModel(OutputStream out) throws XGBoostError, IOException
out
- The output streamXGBoostError
IOException
public void saveModel(OutputStream out, String format) throws XGBoostError, IOException
out
- The output streamformat
- The model format (ubj, json, deprecated)XGBoostError
IOException
public String[] getModelDump(String featureMap, boolean withStats) throws XGBoostError
withStats
- Controls whether the split statistics are output.XGBoostError
- native errorpublic String[] getModelDump(String featureMap, boolean withStats, String format) throws XGBoostError
XGBoostError
public String[] getModelDump(String[] featureNames, boolean withStats) throws XGBoostError
featureNames
- Names of the features.XGBoostError
public String[] getModelDump(String[] featureNames, boolean withStats, String format) throws XGBoostError
XGBoostError
public Map<String,Integer> getFeatureScore(String[] featureNames) throws XGBoostError
XGBoostError
- native errorpublic Map<String,Integer> getFeatureScore(String featureMap) throws XGBoostError
XGBoostError
- native errorpublic Map<String,Double> getScore(String[] featureNames, String importanceType) throws XGBoostError
XGBoostError
- native errorpublic Map<String,Double> getScore(String featureMap, String importanceType) throws XGBoostError
XGBoostError
- native errorpublic byte[] toByteArray() throws XGBoostError
XGBoostError
- native errorpublic byte[] toByteArray(String format) throws XGBoostError
format
- The output format. Available options are "json", "ubj" and "deprecated".XGBoostError
- native errorpublic long getNumFeature() throws XGBoostError
XGBoostError
public int getNumBoostedRound() throws XGBoostError
XGBoostError
protected void finalize() throws Throwable
public void dispose()
public void write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output)
write
in interface com.esotericsoftware.kryo.KryoSerializable
public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input)
read
in interface com.esotericsoftware.kryo.KryoSerializable
Copyright © 2024. All rights reserved.