xgboost
| | 类型定义 | 函数
c_api.h 文件参考

XGBoost 的 C API,用于与其他语言的接口。更多...

#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
c_api.h 的包含依赖图

转到此文件的源代码。

结构  XGBoostBatchCSR
 XGBoost 数据迭代中使用的迷你批次。更多...
 

#define XGB_EXTERN_C
 
#define XGB_DLL   XGB_EXTERN_C __attribute__ ((visibility ("default")))
 

类型定义

typedef uint64_t bst_ulong
 
typedef void * DMatrixHandle
 DMatrix 的句柄更多...
 
typedef void * BoosterHandle
 Booster 的句柄更多...
 
typedef void * DataIterHandle
 外部数据迭代器的句柄更多...
 
typedef void * DataHolderHandle
 内部数据持有者的句柄。更多...
 
typedef int XGBCallbackSetData(DataHolderHandle handle, XGBoostBatchCSR batch)
 设置数据到句柄的回调函数。更多...
 
typedef int XGBCallbackDataIterNext(DataIterHandle data_handle, XGBCallbackSetData *set_function, DataHolderHandle set_function_handle)
 数据读取回调函数。迭代器将能够提供数据中的批次子集。更多...
 
typedef int XGDMatrixCallbackNext(DataIterHandle iter)
 获取下一批数据回调函数原型。更多...
 
typedef void DataIterResetCallback(DataIterHandle handle)
 重置外部迭代器回调函数原型。更多...
 
typedef void * TrackerHandle
 Tracker 的句柄。更多...
 

函数

void XGBoostVersion (int *major, int *minor, int *patch)
 返回当前使用的 XGBoost 库版本。更多...
 
int XGBuildInfo (char const **out)
 获取共享库的编译信息。更多...
 
const char * XGBGetLastError ()
 获取上次错误的字符串消息更多...
 
int XGBRegisterLogCallback (void(*callback)(const char *))
 注册用于 LOG(INFO) 消息的回调函数 – 有用的非错误消息。注意:此函数可以被多个线程调用。回调函数将在注册它的线程上运行更多...
 
int XGBSetGlobalConfig (char const *config)
 设置全局配置(适用于全局的参数集合)。此函数接受表示要配置的全局作用域参数的键值对列表。键值对列表以 JSON 字符串形式传递。更多...
 
int XGBGetGlobalConfig (char const **out_config)
 获取当前全局配置(适用于全局的参数集合)。更多...
 
int XGDMatrixCreateFromFile (const char *fname, int silent, DMatrixHandle *out)
 从文件加载数据矩阵更多...
 
int XGDMatrixCreateFromURI (char const *config, DMatrixHandle *out)
 从 URI 加载数据矩阵更多...
 
int XGDMatrixCreateFromColumnar (char const *data, char const *config, DMatrixHandle *out)
 从列式数据创建 DMatrix。(表格)更多...
 
int XGDMatrixCreateFromCSR (char const *indptr, char const *indices, char const *data, bst_ulong ncol, char const *config, DMatrixHandle *out)
 从 CSR 矩阵创建 DMatrix。更多...
 
int XGDMatrixCreateFromDense (char const *data, char const *config, DMatrixHandle *out)
 从密集数组创建 DMatrix。更多...
 
int XGDMatrixCreateFromCSC (char const *indptr, char const *indices, char const *data, bst_ulong nrow, char const *config, DMatrixHandle *out)
 从 CSC 矩阵创建 DMatrix。更多...
 
int XGDMatrixCreateFromMat (const float *data, bst_ulong nrow, bst_ulong ncol, float missing, DMatrixHandle *out)
 从密集矩阵创建矩阵内容更多...
 
int XGDMatrixCreateFromMat_omp (const float *data, bst_ulong nrow, bst_ulong ncol, float missing, DMatrixHandle *out, int nthread)
 从密集矩阵创建矩阵内容更多...
 
int XGDMatrixCreateFromCudaColumnar (char const *data, char const *config, DMatrixHandle *out)
 从 CUDA 列式格式创建 DMatrix。(cuDF)更多...
 
int XGDMatrixCreateFromCudaArrayInterface (char const *data, char const *config, DMatrixHandle *out)
 从 CUDA 数组创建 DMatrix。更多...
 
int XGDMatrixCreateFromDataIter (DataIterHandle data_handle, XGBCallbackDataIterNext *callback, const char *cache_info, float missing, DMatrixHandle *out)
 从数据迭代器创建 DMatrix。更多...
 
int XGProxyDMatrixCreate (DMatrixHandle *out)
 为设置数据创建 DMatrix 代理,可由 XGDMatrixFree 释放。更多...
 
int XGDMatrixCreateFromCallback (DataIterHandle iter, DMatrixHandle proxy, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, char const *config, DMatrixHandle *out)
 使用数据迭代器创建外部内存 DMatrix。更多...
 
int XGQuantileDMatrixCreateFromCallback (DataIterHandle iter, DMatrixHandle proxy, DataIterHandle ref, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, char const *config, DMatrixHandle *out)
 使用数据迭代器创建分位数 DMatrix。更多...
 
int XGExtMemQuantileDMatrixCreateFromCallback (DataIterHandle iter, DMatrixHandle proxy, DataIterHandle ref, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, char const *config, DMatrixHandle *out)
 创建由外部内存支持的分位数 DMatrix。更多...
 
int XGProxyDMatrixSetDataCudaArrayInterface (DMatrixHandle handle, const char *data)
 在 DMatrix 代理上设置数据。更多...
 
int XGProxyDMatrixSetDataColumnar (DMatrixHandle handle, char const *data)
 在 DMatrix 代理上设置列式(表格)数据。更多...
 
int XGProxyDMatrixSetDataCudaColumnar (DMatrixHandle handle, const char *data)
 在 DMatrix 代理上设置基于 CUDA 的列式(表格)数据。更多...
 
int XGProxyDMatrixSetDataDense (DMatrixHandle handle, char const *data)
 在 DMatrix 代理上设置数据。更多...
 
int XGProxyDMatrixSetDataCSR (DMatrixHandle handle, char const *indptr, char const *indices, char const *data, bst_ulong ncol)
 在 DMatrix 代理上设置数据。更多...
 
int XGDMatrixSliceDMatrix (DMatrixHandle handle, const int *idxset, bst_ulong len, DMatrixHandle *out)
 从现有矩阵的切片内容创建新的 DMatrix更多...
 
int XGDMatrixSliceDMatrixEx (DMatrixHandle handle, const int *idxset, bst_ulong len, DMatrixHandle *out, int allow_groups)
 从现有矩阵的切片内容创建新的 DMatrix更多...
 
int XGDMatrixFree (DMatrixHandle handle)
 释放数据矩阵中的空间更多...
 
int XGDMatrixSaveBinary (DMatrixHandle handle, const char *fname, int silent)
 将 DMatrix 对象保存到文件。不支持 `QuantileDMatrix` 和外部内存 DMatrix。更多...
 
int XGDMatrixSetInfoFromInterface (DMatrixHandle handle, char const *field, char const *data)
 将数组接口中的内容设置到信息内容中。更多...
 
int XGDMatrixSetFloatInfo (DMatrixHandle handle, const char *field, const float *array, bst_ulong len)
 将浮点向量设置到信息内容中更多...
 
int XGDMatrixSetUIntInfo (DMatrixHandle handle, const char *field, const unsigned *array, bst_ulong len)
 
int XGDMatrixSetStrFeatureInfo (DMatrixHandle handle, const char *field, const char **features, const bst_ulong size)
 设置所有特征的字符串编码信息。更多...
 
int XGDMatrixGetStrFeatureInfo (DMatrixHandle handle, const char *field, bst_ulong *size, const char ***out_features)
 获取所有特征的字符串编码信息。更多...
 
int XGDMatrixSetDenseInfo (DMatrixHandle handle, const char *field, void const *data, bst_ulong size, int type)
 
int XGDMatrixGetFloatInfo (const DMatrixHandle handle, const char *field, bst_ulong *out_len, const float **out_dptr)
 从矩阵获取浮点信息向量。更多...
 
int XGDMatrixGetUIntInfo (const DMatrixHandle handle, const char *field, bst_ulong *out_len, const unsigned **out_dptr)
 从矩阵获取 uint32 信息向量更多...
 
int XGDMatrixNumRow (DMatrixHandle handle, bst_ulong *out)
 获取行数。更多...
 
int XGDMatrixNumCol (DMatrixHandle handle, bst_ulong *out)
 获取列数更多...
 
int XGDMatrixNumNonMissing (DMatrixHandle handle, bst_ulong *out)
 从 DMatrix 获取有效值数量。更多...
 
int XGDMatrixDataSplitMode (DMatrixHandle handle, bst_ulong *out)
 从 DMatrix 获取数据拆分模式。更多...
 
int XGDMatrixGetDataAsCSR (DMatrixHandle const handle, char const *config, bst_ulong *out_indptr, unsigned *out_indices, float *out_data)
 将 DMatrix 中的预测变量作为 CSR 矩阵返回以进行测试。如果这是量化 DMatrix,则返回量化值。更多...
 
int XGDMatrixGetQuantileCut (DMatrixHandle const handle, char const *config, char const **out_indptr, char const **out_data)
 导出用于训练基于直方图的模型(如 `hist` 和 `approx`)的分位数切点。有助于模型压缩。更多...
 
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)
 从梯度 booster 获取增强轮次数量。当 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 XGBoosterPredict (BoosterHandle handle, DMatrixHandle dmat, int option_mask, unsigned ntree_limit, int training, bst_ulong *out_len, const float **out_result)
 基于 dmat 进行预测(已弃用,请改用 XGBoosterPredictFromDMatrix更多...
 
int XGBoosterPredictFromDMatrix (BoosterHandle handle, DMatrixHandle dmat, char const *config, bst_ulong const **out_shape, bst_ulong *out_dim, float const **out_result)
 从 DMatrix 进行预测,取代 XGBoosterPredict更多...
 
int XGBoosterPredictFromDense (BoosterHandle handle, char const *values, char const *config, DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
 从 CPU 密集矩阵进行原地预测。更多...
 
int XGBoosterPredictFromColumnar (BoosterHandle handle, char const *values, char const *config, DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
 从 CPU 列式数据进行原地预测。(表格)更多...
 
int XGBoosterPredictFromCSR (BoosterHandle handle, char const *indptr, char const *indices, char const *values, bst_ulong ncol, char const *config, DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
 从 CPU CSR 矩阵进行原地预测。更多...
 
int XGBoosterPredictFromCudaArray (BoosterHandle handle, char const *values, char const *config, DMatrixHandle proxy, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
 从 CUDA 密集矩阵进行原地预测(Python 中的 cupy)。更多...
 
int XGBoosterPredictFromCudaColumnar (BoosterHandle handle, char const *data, char const *config, DMatrixHandle proxy, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
 从 CUDA 密集数据框进行原地预测(Python 中的 cuDF)。更多...
 
int XGBoosterLoadModel (BoosterHandle handle, const char *fname)
 从现有文件加载模型。更多...
 
int XGBoosterSaveModel (BoosterHandle handle, const char *fname)
 将模型保存到现有文件。更多...
 
int XGBoosterLoadModelFromBuffer (BoosterHandle handle, const void *buf, bst_ulong len)
 从内存缓冲区加载模型更多...
 
int XGBoosterSaveModelToBuffer (BoosterHandle handle, char const *config, bst_ulong *out_len, char const **out_dptr)
 将模型保存为原始字节,返回数组的头部。用户必须在下一次 xgboost 调用之前复制结果。更多...
 
int XGBoosterSerializeToBuffer (BoosterHandle handle, bst_ulong *out_len, const char **out_dptr)
 基于内存快照的序列化方法。将所有状态保存到缓冲区。更多...
 
int XGBoosterUnserializeFromBuffer (BoosterHandle handle, const void *buf, bst_ulong len)
 基于内存快照的序列化方法。加载从 XGBoosterSerializeToBuffer 返回的缓冲区。更多...
 
int XGBoosterSaveJsonConfig (BoosterHandle handle, bst_ulong *out_len, char const **out_str)
 将 XGBoost 的内部配置保存到 JSON 文档中。目前此支持是实验性的,函数签名将来可能会在不通知的情况下更改。更多...
 
int XGBoosterLoadJsonConfig (BoosterHandle handle, char const *config)
 从 JSON 文档加载 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,并且具有多种重要性类型定义。更多...
 
int XGTrackerCreate (char const *config, TrackerHandle *handle)
 创建新的 tracker。更多...
 
int XGTrackerWorkerArgs (TrackerHandle handle, char const **args)
 获取运行 worker 所需的参数。这应该在 XGTrackerRun() 之后调用。更多...
 
int XGTrackerRun (TrackerHandle handle, char const *config)
 启动 tracker。tracker 在后台运行,此函数在 tracker 启动后返回。更多...
 
int XGTrackerWaitFor (TrackerHandle handle, char const *config)
 等待 tracker 完成,应该在 XGTrackerRun() 之后调用。此函数将阻塞,直到 tracker 任务完成或达到超时。更多...
 
int XGTrackerFree (TrackerHandle handle)
 释放 tracker 实例。这应该在 XGTrackerWaitFor() 之后调用。如果 tracker 没有正确等待,此函数将关闭与 tracker 的所有连接,可能导致未定义行为。更多...
 
int XGCommunicatorInit (char const *config)
 初始化集体通信器。更多...
 
int XGCommunicatorFinalize (void)
 终止集体通信器。更多...
 
int XGCommunicatorGetRank (void)
 获取当前进程的排名。更多...
 
int XGCommunicatorGetWorldSize (void)
 获取进程总数。更多...
 
int XGCommunicatorIsDistributed (void)
 获取通信器是否为分布式。更多...
 
int XGCommunicatorPrint (char const *message)
 将消息打印到 tracker。更多...
 
int XGCommunicatorGetProcessorName (const char **name_str)
 获取处理器名称。更多...
 
int XGCommunicatorBroadcast (void *send_receive_buffer, size_t size, int root)
 将内存区域从根节点广播到所有其他节点。此函数不是线程安全的。更多...
 
int XGCommunicatorAllreduce (void *send_receive_buffer, size_t count, int data_type, int op)
 执行原地 allreduce。此函数不是线程安全的。更多...
 

详细描述

XGBoost 的 C API,用于与其他语言接口。

版权所有 2015-2025, XGBoost 贡献者

作者
陈天奇

宏定义文档

◆ XGB_DLL

#define XGB_DLL   XGB_EXTERN_C __attribute__ ((visibility ("default")))

◆ XGB_EXTERN_C

#define XGB_EXTERN_C

类型定义文档

◆ bst_ulong

typedef uint64_t bst_ulong