xgboost
|
Booster
类是 XGBoost 的梯度提升模型。 更多...
模块 | |
预测 | |
这些函数用于运行预测和解释算法。 | |
序列化 | |
根据用例,有多种方法可以序列化 Booster 对象。 | |
函数 | |
int | XGBoosterCreate (const DMatrixHandle dmats[], bst_ulong len, BoosterHandle *out) |
创建一个 XGBoost 学习器 (booster) 更多... | |
int | XGBoosterFree (BoosterHandle handle) |
删除 booster。 更多... | |
int | XGBoosterReset (BoosterHandle handle) |
重置 booster 对象,释放训练中使用的数据缓存。 更多... | |
int | XGBoosterSlice (BoosterHandle handle, int begin_layer, int end_layer, int step, BoosterHandle *out) |
使用 boosting 索引对模型进行切片。切片 m:n 表示选取在 boosting 轮次 m, (m+1), (m+2), ..., (n-1) 期间拟合的所有树。 更多... | |
int | XGBoosterBoostedRounds (BoosterHandle handle, int *out) |
获取梯度增强器的 boosting 轮次数。当 process_type 为 update 时,由于树被移除,此数值可能会下降。 更多... | |
int | XGBoosterSetParam (BoosterHandle handle, const char *name, const char *value) |
设置参数 更多... | |
int | XGBoosterGetNumFeature (BoosterHandle handle, bst_ulong *out) |
获取特征数量 更多... | |
int | XGBoosterUpdateOneIter (BoosterHandle handle, int iter, DMatrixHandle dtrain) |
使用 dtrain 更新模型一个轮次 更多... | |
int | XGBoosterBoostOneIter (BoosterHandle handle, DMatrixHandle dtrain, float *grad, float *hess, bst_ulong len) |
int | XGBoosterTrainOneIter (BoosterHandle handle, DMatrixHandle dtrain, int iter, char const *grad, char const *hess) |
使用梯度和 Hessian 更新模型。这用于使用自定义目标函数进行训练。 更多... | |
int | XGBoosterEvalOneIter (BoosterHandle handle, int iter, DMatrixHandle dmats[], const char *evnames[], bst_ulong len, const char **out_result) |
获取 xgboost 的评估统计信息 更多... | |
int | XGBoosterDumpModel (BoosterHandle handle, const char *fmap, int with_stats, bst_ulong *out_len, const char ***out_dump_array) |
转储模型,返回表示模型转储的字符串数组 更多... | |
int | XGBoosterDumpModelEx (BoosterHandle handle, const char *fmap, int with_stats, const char *format, bst_ulong *out_len, const char ***out_dump_array) |
转储模型,返回表示模型转储的字符串数组 更多... | |
int | XGBoosterDumpModelWithFeatures (BoosterHandle handle, int fnum, const char **fname, const char **ftype, int with_stats, bst_ulong *out_len, const char ***out_models) |
转储模型,返回表示模型转储的字符串数组 更多... | |
int | XGBoosterDumpModelExWithFeatures (BoosterHandle handle, int fnum, const char **fname, const char **ftype, int with_stats, const char *format, bst_ulong *out_len, const char ***out_models) |
转储模型,返回表示模型转储的字符串数组 更多... | |
int | XGBoosterGetAttr (BoosterHandle handle, const char *key, const char **out, int *success) |
从 Booster 获取字符串属性。 更多... | |
int | XGBoosterSetAttr (BoosterHandle handle, const char *key, const char *value) |
设置或删除字符串属性。 更多... | |
int | XGBoosterGetAttrNames (BoosterHandle handle, bst_ulong *out_len, const char ***out) |
从 Booster 获取所有属性名称。 更多... | |
int | XGBoosterSetStrFeatureInfo (BoosterHandle handle, const char *field, const char **features, const bst_ulong size) |
在 Booster 中设置字符串编码的特征信息,类似于 DMatrix 中的特征信息。 更多... | |
int | XGBoosterGetStrFeatureInfo (BoosterHandle handle, const char *field, bst_ulong *len, const char ***out_features) |
从 Booster 获取字符串编码的特征信息,类似于 DMatrix 中的特征信息。 更多... | |
int | XGBoosterFeatureScore (BoosterHandle handle, const char *config, bst_ulong *out_n_features, char const ***out_features, bst_ulong *out_dim, bst_ulong const **out_shape, float const **out_scores) |
计算树模型的特征得分。用于线性模型时,只定义了 weight 重要性类型,输出得分是多类别模型的行主序矩阵,形状为 [n_features, n_classes]。对于树模型,out_n_feature 始终等于 out_n_scores,并有多种重要性类型定义。 更多... | |
Booster
类是 XGBoost 的梯度提升模型。
训练期间,booster 对象有许多缓存用于提高性能。除了梯度和预测,它还包括运行时缓冲区,如叶子分区。这些缓冲区与 Booster 对象一起存在,直到调用 XGBoosterReset() 或通过 XGBoosterFree() 删除 booster。
int XGBoosterBoostedRounds | ( | BoosterHandle | handle, |
int * | out | ||
) |
获取梯度增强器的 boosting 轮次数。当 process_type 为 update 时,由于树被移除,此数值可能会下降。
handle | booster 的句柄。 |
out | 指向输出整数的指针。 |
int XGBoosterBoostOneIter | ( | BoosterHandle | handle, |
DMatrixHandle | dtrain, | ||
float * | grad, | ||
float * | hess, | ||
bst_ulong | len | ||
) |
int XGBoosterCreate | ( | const DMatrixHandle | dmats[], |
bst_ulong | len, | ||
BoosterHandle * | out | ||
) |
创建一个 XGBoost 学习器 (booster)
dmats | 设置为由 booster 缓存的矩阵。 |
len | dmats 的长度 |
out | 结果 booster 的句柄 |
int XGBoosterDumpModel | ( | BoosterHandle | handle, |
const char * | fmap, | ||
int | with_stats, | ||
bst_ulong * | out_len, | ||
const char *** | out_dump_array | ||
) |
转储模型,返回表示模型转储的字符串数组
handle | handle |
fmap | fmap 名称可以为空字符串 |
with_stats | 是否转储统计信息 |
out_len | 输出数组的长度 |
out_dump_array | 指向存储每个模型转储的指针 |
int XGBoosterDumpModelEx | ( | BoosterHandle | handle, |
const char * | fmap, | ||
int | with_stats, | ||
const char * | format, | ||
bst_ulong * | out_len, | ||
const char *** | out_dump_array | ||
) |
转储模型,返回表示模型转储的字符串数组
handle | handle |
fmap | fmap 名称可以为空字符串 |
with_stats | 是否转储统计信息 |
format | 模型转储的格式 |
out_len | 输出数组的长度 |
out_dump_array | 指向存储每个模型转储的指针 |
int XGBoosterDumpModelExWithFeatures | ( | BoosterHandle | handle, |
int | fnum, | ||
const char ** | fname, | ||
const char ** | ftype, | ||
int | with_stats, | ||
const char * | format, | ||
bst_ulong * | out_len, | ||
const char *** | out_models | ||
) |
转储模型,返回表示模型转储的字符串数组
handle | handle |
fnum | 特征数量 |
fname | 特征名称 |
ftype | 特征类型 |
with_stats | 是否转储统计信息 |
format | 模型转储的格式 |
out_len | 输出数组的长度 |
out_models | 指向存储每个模型转储的指针 |
int XGBoosterDumpModelWithFeatures | ( | BoosterHandle | handle, |
int | fnum, | ||
const char ** | fname, | ||
const char ** | ftype, | ||
int | with_stats, | ||
bst_ulong * | out_len, | ||
const char *** | out_models | ||
) |
转储模型,返回表示模型转储的字符串数组
handle | handle |
fnum | 特征数量 |
fname | 特征名称 |
ftype | 特征类型 |
with_stats | 是否转储统计信息 |
out_len | 输出数组的长度 |
out_models | 指向存储每个模型转储的指针 |
int XGBoosterEvalOneIter | ( | BoosterHandle | handle, |
int | iter, | ||
DMatrixHandle | dmats[], | ||
const char * | evnames[], | ||
bst_ulong | len, | ||
const char ** | out_result | ||
) |
获取 xgboost 的评估统计信息
handle | handle |
iter | 当前迭代轮次 |
dmats | 指向待评估数据的指针 |
evnames | 指向每个数据名称的指针 |
len | dmats 的长度 |
out_result | 包含评估统计信息的字符串 |
int XGBoosterFeatureScore | ( | BoosterHandle | handle, |
const char * | config, | ||
bst_ulong * | out_n_features, | ||
char const *** | out_features, | ||
bst_ulong * | out_dim, | ||
bst_ulong const ** | out_shape, | ||
float const ** | out_scores | ||
) |
计算树模型的特征得分。用于线性模型时,只定义了 weight
重要性类型,输出得分是多类别模型的行主序矩阵,形状为 [n_features, n_classes]。对于树模型,out_n_feature 始终等于 out_n_scores,并有多种重要性类型定义。
handle | Booster 的一个实例 |
config | 计算得分的参数,编码为 JSON 格式。接受的 JSON 键有
|
out_n_features | 输出特征名称的长度。 |
out_features | 作为特征名称的字符串数组,顺序与输出得分相同。 |
out_dim | 输出特征得分的维度。 |
out_shape | 输出特征得分的形状,长度为 out_dim 。 |
out_scores | 作为特征得分的浮点数数组,形状为 out_shape 。 |
int XGBoosterFree | ( | BoosterHandle | handle | ) |
删除 booster。
handle | 待释放的句柄。 |
int XGBoosterGetAttr | ( | BoosterHandle | handle, |
const char * | key, | ||
const char ** | out, | ||
int * | success | ||
) |
从 Booster 获取字符串属性。
handle | handle |
key | 属性的键。 |
out | 结果属性,如果属性不存在则可以为 NULL。 |
success | 结果是否包含在 out 中。 |
int XGBoosterGetAttrNames | ( | BoosterHandle | handle, |
bst_ulong * | out_len, | ||
const char *** | out | ||
) |
从 Booster 获取所有属性名称。
handle | handle |
out_len | 用于存储输出长度的参数 |
out | 指向存储输出属性字符串的指针 |
int XGBoosterGetNumFeature | ( | BoosterHandle | handle, |
bst_ulong * | out | ||
) |
int XGBoosterGetStrFeatureInfo | ( | BoosterHandle | handle, |
const char * | field, | ||
bst_ulong * | len, | ||
const char *** | out_features | ||
) |
从 Booster 获取字符串编码的特征信息,类似于 DMatrix 中的特征信息。
接受的字段有
调用者负责在下次调用 XGBoost 的任何 API 函数之前复制出数据。
handle | Booster 的一个实例 |
field | 字段名称 |
len | 输出指针 features 的大小(返回的字符串数量)。 |
out_features | 指向字符串数组的指针的地址。结果存储在线程局部内存中。 |
int XGBoosterReset | ( | BoosterHandle | handle | ) |
重置 booster 对象,释放训练中使用的数据缓存。
int XGBoosterSetAttr | ( | BoosterHandle | handle, |
const char * | key, | ||
const char * | value | ||
) |
设置或删除字符串属性。
handle | handle |
key | 属性的键。 |
value | 要保存的值。如果为 nullptr,则属性将被删除。 |
int XGBoosterSetParam | ( | BoosterHandle | handle, |
const char * | name, | ||
const char * | value | ||
) |
int XGBoosterSetStrFeatureInfo | ( | BoosterHandle | handle, |
const char * | field, | ||
const char ** | features, | ||
const bst_ulong | size | ||
) |
在 Booster 中设置字符串编码的特征信息,类似于 DMatrix 中的特征信息。
接受的字段有
handle | Booster 的一个实例 |
field | 字段名称 |
features | 指向字符串数组的指针。 |
size | features 指针的大小(传入的字符串数量)。 |
int XGBoosterSlice | ( | BoosterHandle | handle, |
int | begin_layer, | ||
int | end_layer, | ||
int | step, | ||
BoosterHandle * | out | ||
) |
使用 boosting 索引对模型进行切片。切片 m:n 表示选取在 boosting 轮次 m, (m+1), (m+2), ..., (n-1) 期间拟合的所有树。
handle | 待切片的 Booster。 |
begin_layer | 切片的起始 |
end_layer | 切片的结束;end_layer=0 等同于 end_layer=num_boost_round |
step | 切片的步长 |
out | 切片后的 booster。 |
int XGBoosterTrainOneIter | ( | BoosterHandle | handle, |
DMatrixHandle | dtrain, | ||
int | iter, | ||
char const * | grad, | ||
char const * | hess | ||
) |
使用梯度和 Hessian 更新模型。这用于使用自定义目标函数进行训练。
handle | handle |
dtrain | 训练数据。 |
iter | 当前迭代轮次。使用训练继续时,计数应重新开始。 |
grad | 梯度的 Json 编码 __(cuda)_array_interface__。 |
hess | Hessian 的 Json 编码 __(cuda)_array_interface__。 |
int XGBoosterUpdateOneIter | ( | BoosterHandle | handle, |
int | iter, | ||
DMatrixHandle | dtrain | ||
) |
使用 dtrain 更新模型一个轮次
handle | handle |
iter | 当前迭代轮次 |
dtrain | 训练数据 |