public class Booster extends Object implements Serializable, com.esotericsoftware.kryo.KryoSerializable
| 修饰符和类型 | 类和描述 | 
|---|---|
| 静态类  | Booster.FeatureImportanceType支持的特征重要性类型: WEIGHT = 特征用于决定拆分的节点数 GAIN = 特征每次拆分的平均信息增益 COVER = 特征每次拆分的平均覆盖 TOTAL_GAIN = 特征所有拆分的总信息增益 TOTAL_COVER = 特征所有拆分的总覆盖 | 
| 静态类  | Booster.PredictionType此枚举定义了要进行的预测类型,并用于就地预测。 | 
| 修饰符和类型 | 字段和说明 | 
|---|---|
| static String | DEFAULT_FORMAT | 
| 修饰符和类型 | 方法和说明 | 
|---|---|
| void | boost(DMatrix dtrain, float[] grad, float[] hess)已弃用。  | 
| void | boost(DMatrix dtrain, int iter, float[] grad, float[] hess)使用给定的梯度和Hessian更新 | 
| void | dispose() | 
| String | evalSet(DMatrix[] evalMatrixs, String[] evalNames, IEvaluation eval)使用自定义评估类评估Booster模型 | 
| String | evalSet(DMatrix[] evalMatrixs, String[] evalNames, IEvaluation eval, float[] metricsOut) | 
| String | evalSet(DMatrix[] evalMatrixs, String[] evalNames, int iter)使用给定的DMatrix评估Booster模型。 | 
| String | evalSet(DMatrix[] evalMatrixs, String[] evalNames, int iter, float[] metricsOut)使用给定的DMatrix评估Booster模型。 | 
| protected void | finalize() | 
| String | getAttr(String key)根据提供的键从Booster中获取属性值。 | 
| Map<String,String> | getAttrs()获取存储在Booster中的属性,以Map形式返回。 | 
| String[] | getFeatureNames()从Booster中获取所有特征名称。 | 
| Map<String,Integer> | getFeatureScore(String featureMap)获取每个特征的重要性 | 
| Map<String,Integer> | getFeatureScore(String[] featureNames)获取具有指定特征名称的每个特征的重要性。 | 
| String[] | getFeatureTypes()从Booster获取特征类型。 | 
| String[] | getModelDump(String[] featureNames, boolean withStats)以指定特征名称获取模型的转储(字符串数组形式)。 | 
| String[] | getModelDump(String[] featureNames, boolean withStats, String format)以指定特征图、统计信息和指定格式获取模型的转储(字符串数组形式)。 | 
| String[] | getModelDump(String featureMap, boolean withStats)将模型转储为字符串数组 | 
| String[] | getModelDump(String featureMap, boolean withStats, String format)以指定特征图、统计信息和指定格式获取模型的转储(字符串数组形式)。 | 
| int | getNumBoostedRound() | 
| long | getNumFeature()获取模型特征的数量。 | 
| Map<String,Double> | getScore(String[] featureNames, String importanceType)获取增益或覆盖(平均或总和)的特征重要性 | 
| Map<String,Double> | getScore(String featureMap, String importanceType)获取增益或覆盖(平均或总和)的特征重要性,带有特征名称 | 
| float[][] | inplace_predict(float[] data, int nrow, int ncol, float missing)执行线程安全的预测。 | 
| float[][] | inplace_predict(float[] data, int nrow, int ncol, float missing, int[] iteration_range)执行线程安全的预测。 | 
| float[][] | inplace_predict(float[] data, int nrow, int ncol, float missing, int[] iteration_range, Booster.PredictionType predict_type, float[] base_margin)执行线程安全的预测。 | 
| float[][] | predict(DMatrix data)使用DMatrix格式的测试数据进行预测。 | 
| float[][] | predict(DMatrix data, boolean outputMargin)使用DMatrix格式的测试数据和输出边距进行预测。 | 
| float[][] | predict(DMatrix data, boolean outputMargin, int treeLimit)带有所有选项的高级预测函数。 | 
| float[][] | predictContrib(DMatrix data, int treeLimit)输出给定数据对预测的特征贡献 | 
| float[][] | predictLeaf(DMatrix data, int treeLimit)根据给定数据预测叶子索引 | 
| void | read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) | 
| void | saveModel(OutputStream out)将模型保存到以输出流形式打开的文件。 | 
| void | saveModel(OutputStream out, String format)将模型保存到以输出流形式打开的文件。 | 
| void | saveModel(String modelPath)将模型保存到modelPath | 
| void | setAttr(String key, String value)为Booster设置属性键值对。 | 
| void | setAttrs(Map<String,String> attrs)为Booster设置多个属性键值对。 | 
| void | setFeatureNames(String[] featureNames)为Booster设置特征名称。 | 
| void | setFeatureTypes(String[] featureTypes)为Booster设置特征类型。 | 
| void | setParam(String key, Object value)为Booster设置参数。 | 
| void | setParams(Map<String,Object> params)为Booster设置参数。 | 
| byte[] | toByteArray()以UBJSON ("ubj") 格式将模型保存到原始字节数组中。 | 
| byte[] | toByteArray(String format)将模型保存到原始字节数组。 | 
| void | update(DMatrix dtrain, int iter)更新助推器一次迭代。 | 
| void | update(DMatrix dtrain, int iter, IObjective obj)使用自定义对象函数进行更新 | 
| void | update(DMatrix dtrain, IObjective obj)已弃用。  | 
| void | write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output) | 
public final void setParam(String key, Object value) throws XGBoostError
key - 参数名称value - 参数值XGBoostError - 原生错误public void setParams(Map<String,Object> params) throws XGBoostError
params - 参数键值对映射XGBoostError - 原生错误public final Map<String,String> getAttrs() throws XGBoostError
XGBoostError - 原生错误public final String getAttr(String key) throws XGBoostError
key - 属性键XGBoostError - 原生错误public final void setAttr(String key, String value) throws XGBoostError
key - 属性键value - 属性值XGBoostError - 原生错误public void setAttrs(Map<String,String> attrs) throws XGBoostError
attrs - 属性键值对映射XGBoostError - 原生错误public final String[] getFeatureNames() throws XGBoostError
XGBoostErrorpublic void setFeatureNames(String[] featureNames) throws XGBoostError
featureNames - 所有特征名称的数组。XGBoostErrorpublic final String[] getFeatureTypes() throws XGBoostError
XGBoostErrorpublic void setFeatureTypes(String[] featureTypes) throws XGBoostError
featureTypes - 所有特征类型的数组。XGBoostErrorpublic void update(DMatrix dtrain, int iter) throws XGBoostError
dtrain - 训练数据iter - 当前迭代次数XGBoostError - 原生错误@Deprecated public void update(DMatrix dtrain, IObjective obj) throws XGBoostError
XGBoostErrorpublic void update(DMatrix dtrain, int iter, IObjective obj) throws XGBoostError
dtrain - 训练数据iter - 当前训练迭代。obj - 自定义目标类XGBoostError - 原生错误@Deprecated public void boost(DMatrix dtrain, float[] grad, float[] hess) throws XGBoostError
XGBoostErrorpublic void boost(DMatrix dtrain, int iter, float[] grad, float[] hess) throws XGBoostError
dtrain - 训练数据iter - 当前训练迭代。grad - 梯度一阶导数hess - 梯度二阶导数XGBoostError - 原生错误public String evalSet(DMatrix[] evalMatrixs, String[] evalNames, int iter) throws XGBoostError
evalMatrixs - 用于评估的 DMatrixevalNames - 评估 DMatrix 的名称,用于检查结果iter - 当前评估迭代XGBoostError - 原生错误public String evalSet(DMatrix[] evalMatrixs, String[] evalNames, int iter, float[] metricsOut) throws XGBoostError
evalMatrixs - 用于评估的 DMatrixevalNames - 评估 DMatrix 的名称,用于检查结果iter - 当前评估迭代metricsOut - 包含每个 evalMatrix 评估指标的输出数组XGBoostError - 原生错误public String evalSet(DMatrix[] evalMatrixs, String[] evalNames, IEvaluation eval) throws XGBoostError
evalMatrixs - 评估矩阵evalNames - 评估名称eval - 自定义评估器XGBoostError - 原生错误public String evalSet(DMatrix[] evalMatrixs, String[] evalNames, IEvaluation eval, float[] metricsOut) throws XGBoostError
XGBoostErrorpublic float[][] inplace_predict(float[] data,
                                 int nrow,
                                 int ncol,
                                 float missing)
                          throws XGBoostError
data - 用于预测的展平输入特征矩阵nrow - 要进行的预测数量(输入矩阵行数)ncol - 模型中的特征数量(输入矩阵列数)missing - 表示 data 输入矩阵中缺失元素的值XGBoostErrorpublic float[][] inplace_predict(float[] data,
                                 int nrow,
                                 int ncol,
                                 float missing,
                                 int[] iteration_range)
                          throws XGBoostError
data - 用于预测的展平输入特征矩阵nrow - 要进行的预测数量(输入矩阵行数)ncol - 模型中的特征数量(输入矩阵列数)missing - 表示 data 输入矩阵中缺失元素的值iteration_range - 指定用于预测的树层。例如,如果随机森林经过 100 轮训练。指定 `iteration_range=[10, 20)`,则在此预测中仅使用在 [10, 20)(半开集)轮中构建的森林。XGBoostErrorpublic float[][] inplace_predict(float[] data,
                                 int nrow,
                                 int ncol,
                                 float missing,
                                 int[] iteration_range,
                                 Booster.PredictionType predict_type,
                                 float[] base_margin)
                          throws XGBoostError
data - 用于预测的展平输入特征矩阵nrow - 要进行的预测数量(输入矩阵行数)ncol - 模型中的特征数量(输入矩阵列数)missing - 表示 data 输入矩阵中缺失元素的值iteration_range - 指定用于预测的树层。例如,如果随机森林经过 100 轮训练。指定 `iteration_range=[10, 20)`,则在此预测中仅使用在 [10, 20)(半开集)轮中构建的森林。predict_type - 要运行的预测类型。XGBoostErrorpublic float[][] predictLeaf(DMatrix data, int treeLimit) throws XGBoostError
data - 输入数据。treeLimit - 要包含的树的数量,0 表示所有树。XGBoostErrorpublic float[][] predictContrib(DMatrix data, int treeLimit) throws XGBoostError
data - 输入数据。treeLimit - 要包含的树的数量,0 表示所有树。XGBoostErrorpublic float[][] predict(DMatrix data) throws XGBoostError
data - 存储要进行预测的测试输入的 DMatrixXGBoostError - 原生错误public float[][] predict(DMatrix data, boolean outputMargin) throws XGBoostError
data - 存储要进行预测的测试输入的 DMatrixoutputMargin - 输出边距XGBoostErrorpublic float[][] predict(DMatrix data, boolean outputMargin, int treeLimit) throws XGBoostError
data - 存储要进行预测的测试输入的矩阵outputMargin - 输出边距treeLimit - 树的数量限制,0 表示所有树。XGBoostErrorpublic void saveModel(String modelPath) throws XGBoostError
modelPath - 模型路径XGBoostErrorpublic void saveModel(OutputStream out) throws XGBoostError, IOException
out - 输出流XGBoostErrorIOExceptionpublic void saveModel(OutputStream out, String format) throws XGBoostError, IOException
out - 输出流format - 模型格式(ubj, json, deprecated)XGBoostErrorIOExceptionpublic String[] getModelDump(String featureMap, boolean withStats) throws XGBoostError
featureMap - 包含特征映射路径的字符串。withStats - 控制是否输出分割统计信息。XGBoostError - 原生错误public String[] getModelDump(String featureMap, boolean withStats, String format) throws XGBoostError
featureMap - 包含特征映射路径的字符串。withStats - 控制是否输出分割统计信息。format - 模型转储的格式(text, json, ubj)。XGBoostErrorpublic String[] getModelDump(String[] featureNames, boolean withStats) throws XGBoostError
featureNames - 特征名称。XGBoostErrorpublic String[] getModelDump(String[] featureNames, boolean withStats, String format) throws XGBoostError
featureNames - 包含特征名称的字符串数组。withStats - 控制是否输出分割统计信息。format - 模型转储的格式(text, json, ubj)。XGBoostErrorpublic Map<String,Integer> getFeatureScore(String[] featureNames) throws XGBoostError
XGBoostError - 原生错误public Map<String,Integer> getFeatureScore(String featureMap) throws XGBoostError
XGBoostError - 原生错误public Map<String,Double> getScore(String[] featureNames, String importanceType) throws XGBoostError
XGBoostError - 原生错误public Map<String,Double> getScore(String featureMap, String importanceType) throws XGBoostError
XGBoostError - 原生错误public byte[] toByteArray()
                   throws XGBoostError
XGBoostError - 原生错误public byte[] toByteArray(String format) throws XGBoostError
format - 输出格式。可用选项有 "json"、"ubj" 和 "deprecated"。XGBoostError - 原生错误public long getNumFeature()
                   throws XGBoostError
XGBoostErrorpublic int getNumBoostedRound()
                       throws XGBoostError
XGBoostErrorpublic void dispose()
public void write(com.esotericsoftware.kryo.Kryo kryo,
                  com.esotericsoftware.kryo.io.Output output)
write 在接口 com.esotericsoftware.kryo.KryoSerializable中public void read(com.esotericsoftware.kryo.Kryo kryo,
                 com.esotericsoftware.kryo.io.Input input)
read 在接口 com.esotericsoftware.kryo.KryoSerializable中版权所有 © 2025. 保留所有权利。