|
xgboost
|
DMatrix 是 XGBoost 使用的所有算法(包括训练、预测和解释)的基本数据存储。DMatrix 有几种变体,包括正常的 DMatrix(即 CSR 矩阵)、用于节省内存的基于直方图的树方法的 QuantileDMatrix,以及最后一个实验性的基于外部内存的 DMatrix,它在训练期间分批读取数据。后两种变体请参阅 Streaming 组。 更多...

模块 | |
| 流式传输 | |
| 分位数 DMatrix 和外部内存 DMatrix 可以从批量数据创建。 | |
函数 | |
| int | XGDMatrixCreateFromFile (const char *fname, int silent, DMatrixHandle *out) |
| 加载一个数据矩阵 更多... | |
| int | XGDMatrixCreateFromURI (char const *config, DMatrixHandle *out) |
| 加载一个数据矩阵 更多... | |
| 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 | 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) |
| 以 CSR 矩阵形式获取 DMatrix 的预测值(用于测试)。如果是量化 DMatrix,则返回量化值。 更多... | |
| int | XGDMatrixGetQuantileCut (DMatrixHandle const handle, char const *config, char const **out_indptr, char const **out_data) |
导出用于训练基于直方图的模型(如 hist 和 approx)的分位数截断值。对模型压缩很有用。 更多... | |
DMatrix 是 XGBoost 使用的所有算法(包括训练、预测和解释)的基本数据存储。DMatrix 有几种变体,包括正常的 DMatrix(即 CSR 矩阵)、用于节省内存的基于直方图的树方法的 QuantileDMatrix,以及最后一个实验性的基于外部内存的 DMatrix,它在训练期间分批读取数据。后两种变体请参阅 Streaming 组。
| int XGDMatrixCreateFromColumnar | ( | char const * | 数据, |
| char const * | config, | ||
| DMatrixHandle * | out | ||
| ) |
从列式数据创建 DMatrix。(表格)
DMatrix 的一种特殊输入类型是列式格式,它指的是基于列的数据框。XGBoost 可以接受整数和浮点数等数值数据类型,以及称为字典(在 arrow 的术语中)的分类类型。分类类型的添加在 3.1.0 中引入。数据框由列表数组接口表示,每个列对应一个对象。
分类类型由 3 个缓冲区表示:有效性掩码、类别名称(在大多数数据框实现中称为索引)以及用于在行中表示类别的代码。XGBoost 通过接受列表中的两个 JSON 编码的 arrow 数组来消耗分类列。列表中的第一个项是一个 JSON 对象,包含 {"offsets": IntegerArray, "values": StringArray },表示 arrow 列式格式定义的字符串名称。第二个缓冲区是带掩码的整数数组,它存储类别代码以及有效性掩码。
至于数值输入,它们与密集数组相同。
| 数据 | JSON 编码的数组接口列表。 |
| config | 有关详细信息,请参阅 XGDMatrixCreateFromDense。 |
| out | 创建的 DMatrix。 |
| int XGDMatrixCreateFromCSC | ( | char const * | indptr, |
| char const * | indices, | ||
| char const * | 数据, | ||
| bst_ulong | nrow, | ||
| char const * | config, | ||
| DMatrixHandle * | out | ||
| ) |
从 CSC 矩阵创建 DMatrix。
| indptr | JSON 编码的 CSC 中列指针的array_interface。 |
| indices | JSON 编码的 CSC 中行索引的array_interface。 |
| 数据 | JSON 编码的 CSC 中值的array_interface。 |
| nrow | 矩阵的行数。 |
| config | 有关详细信息,请参阅 XGDMatrixCreateFromDense。 |
| out | 创建的 dmatrix。 |
| int XGDMatrixCreateFromCSR | ( | char const * | indptr, |
| char const * | indices, | ||
| char const * | 数据, | ||
| bst_ulong | ncol, | ||
| char const * | config, | ||
| DMatrixHandle * | out | ||
| ) |
从 CSR 矩阵创建 DMatrix。
| indptr | JSON 编码的 CSR 中行指针的array_interface。 |
| indices | JSON编码的CSR中列索引的array_interface。 |
| 数据 | JSON 编码的 CSR 中值的array_interface。 |
| ncol | 列数。 |
| config | 有关详细信息,请参阅 XGDMatrixCreateFromDense。 |
| out | 创建的 dmatrix |
| int XGDMatrixCreateFromCudaArrayInterface | ( | char const * | 数据, |
| char const * | config, | ||
| DMatrixHandle * | out | ||
| ) |
从 CUDA 数组创建 DMatrix。
| 数据 | 用于数组数据的 JSON 编码cuda_array_interface。 |
| config | JSON 编码的配置。必需的字段包括
|
| out | 创建的 dmatrix |
| int XGDMatrixCreateFromCudaColumnar | ( | char const * | 数据, |
| char const * | config, | ||
| DMatrixHandle * | out | ||
| ) |
从 CUDA 列式格式创建 DMatrix。(cuDF)
有关列式格式的简要说明,请参阅 XGDMatrixCreateFromColumnar。
| 数据 | JSON 编码的数组接口列表。 |
| config | 有关详细信息,请参阅 XGDMatrixCreateFromDense。 |
| out | 创建的 dmatrix |
| int XGDMatrixCreateFromDense | ( | char const * | 数据, |
| char const * | config, | ||
| DMatrixHandle * | out | ||
| ) |
从密集数组创建 DMatrix。
数组接口定义在 https://numpy.com.cn/doc/2.1/reference/arrays.interface.html。我们将接口编码为 JSON 对象。
| 数据 | 用于数组值的 JSON 编码array_interface。 |
| config | JSON 编码的配置。必需的字段包括
|
| out | 创建的 DMatrix |
| int XGDMatrixCreateFromFile | ( | const char * | fname, |
| int | silent, | ||
| DMatrixHandle * | out | ||
| ) |
| int XGDMatrixCreateFromMat | ( | const float * | 数据, |
| bst_ulong | nrow, | ||
| bst_ulong | ncol, | ||
| float | missing, | ||
| DMatrixHandle * | out | ||
| ) |
从密集矩阵创建矩阵内容
| 数据 | 指向数据空间的指针 |
| nrow | 行数 |
| ncol | 列数 |
| missing | 哪个值代表缺失值 |
| out | 创建的 dmatrix |
| int XGDMatrixCreateFromMat_omp | ( | const float * | 数据, |
| bst_ulong | nrow, | ||
| bst_ulong | ncol, | ||
| float | missing, | ||
| DMatrixHandle * | out, | ||
| int | nthread | ||
| ) |
从密集矩阵创建矩阵内容
| 数据 | 指向数据空间的指针 |
| nrow | 行数 |
| ncol | 列数 |
| missing | 哪个值代表缺失值 |
| out | 创建的 dmatrix |
| nthread | 线程数(最多可用核心数,如果 <=0 则使用所有核心) |
| int XGDMatrixCreateFromURI | ( | char const * | config, |
| DMatrixHandle * | out | ||
| ) |
加载数据矩阵
| config | 用于 DMatrix 构建的 JSON 编码参数。可接受的字段包括
|
| out | 已加载的数据矩阵 |
| int XGDMatrixDataSplitMode | ( | DMatrixHandle | handle, |
| bst_ulong * | out | ||
| ) |
从 DMatrix 获取数据分割模式。
| handle | 指向 DMatrix 的句柄 |
| out | 数据分割模式的输出 |
| int XGDMatrixFree | ( | DMatrixHandle | handle | ) |
| int XGDMatrixGetDataAsCSR | ( | DMatrixHandle const | handle, |
| char const * | config, | ||
| bst_ulong * | out_indptr, | ||
| unsigned * | out_indices, | ||
| float * | out_data | ||
| ) |
以 CSR 矩阵形式获取 DMatrix 的预测值(用于测试)。如果是量化 DMatrix,则返回量化值。
与大多数 XGBoost C 函数不同,XGDMatrixGetDataAsCSR 的调用者需要为返回缓冲区分配内存,而不是使用 XGBoost 的线程本地内存。这是为了避免分配直到线程退出才能释放的大块内存缓冲区。
| handle | 指向 DMatrix 的句柄 |
| config | JSON 配置字符串。目前它应该是一个空文档,保留供将来使用。 |
| out_indptr | 输出 CSR 矩阵的 indptr。 |
| out_indices | 输出 CSR 矩阵的列索引。 |
| out_data | CSR 矩阵的数据值。 |
| int XGDMatrixGetFloatInfo | ( | const DMatrixHandle | handle, |
| const char * | field, | ||
| bst_ulong * | out_len, | ||
| const float ** | out_dptr | ||
| ) |
从矩阵获取浮点信息向量。
| handle | 一个数据矩阵实例 |
| field | 字段名 |
| out_len | 用于设置结果长度 |
| out_dptr | 指向结果的指针 |
| int XGDMatrixGetQuantileCut | ( | DMatrixHandle const | handle, |
| char const * | config, | ||
| char const ** | out_indptr, | ||
| char const ** | out_data | ||
| ) |
导出用于训练基于直方图的模型(如 hist 和 approx)的分位数截断值。对模型压缩很有用。
| handle | 指向 DMatrix 的句柄 |
| config | JSON 配置字符串。目前它应该是一个空文档,保留供将来使用。 |
| out_indptr | 输出 CSC 矩阵的 indptr,表示为 JSON 编码的 __(cuda_)array_interface__。 |
| out_data | 输出 CSC 矩阵的值,表示为 JSON 编码的 __(cuda_)array_interface__。 |
| int XGDMatrixGetStrFeatureInfo | ( | DMatrixHandle | handle, |
| const char * | field, | ||
| bst_ulong * | size, | ||
| const char *** | out_features | ||
| ) |
获取所有特征的字符串编码信息。
接受的字段有
调用者负责在下一次调用任何 XGBoost API 函数之前复制数据。
| handle | 数据矩阵的一个实例 |
| field | 字段名 |
| size | 输出指针 features 的大小(返回的字符串数量)。 |
| out_features | 指向字符串数组的指针的地址。结果存储在线程本地内存中。 |
| int XGDMatrixGetUIntInfo | ( | const DMatrixHandle | handle, |
| const char * | field, | ||
| bst_ulong * | out_len, | ||
| const unsigned ** | out_dptr | ||
| ) |
从矩阵获取 uint32 信息向量
| handle | 一个数据矩阵实例 |
| field | 字段名 |
| out_len | 字段的长度。 |
| out_dptr | 指向结果的指针 |
| int XGDMatrixNumCol | ( | DMatrixHandle | handle, |
| bst_ulong * | out | ||
| ) |
获取列数
| handle | 指向 DMatrix 的句柄 |
| out | 列数的输出 |
| int XGDMatrixNumNonMissing | ( | DMatrixHandle | handle, |
| bst_ulong * | out | ||
| ) |
从 DMatrix 获取有效值数量。
| handle | 指向 DMatrix 的句柄 |
| out | 非缺失值数量的输出 |
| int XGDMatrixNumRow | ( | DMatrixHandle | handle, |
| bst_ulong * | out | ||
| ) |
获取行数。
| handle | 指向 DMatrix 的句柄 |
| out | 用于保存行数的地址。 |
| int XGDMatrixSaveBinary | ( | DMatrixHandle | handle, |
| const char * | fname, | ||
| int | silent | ||
| ) |
将 DMatrix 对象保存到文件。不支持 QuantileDMatrix 和外部内存 DMatrix。
| handle | 一个数据矩阵实例 |
| fname | 文件名 |
| silent | 保存时打印统计信息 |
| int XGDMatrixSetDenseInfo | ( | DMatrixHandle | handle, |
| const char * | field, | ||
| void const * | 数据, | ||
| bst_ulong | size, | ||
| int | type | ||
| ) |
| int XGDMatrixSetFloatInfo | ( | DMatrixHandle | handle, |
| const char * | field, | ||
| const float * | 数组, | ||
| bst_ulong | 长度 | ||
| ) |
将浮点向量设置为信息中的内容
| handle | 一个数据矩阵实例 |
| field | 字段名,可以是 label、weight |
| 数组 | 指向浮点向量的指针 |
| 长度 | 数组长度 |
| int XGDMatrixSetInfoFromInterface | ( | DMatrixHandle | handle, |
| char const * | field, | ||
| char const * | 数据 | ||
| ) |
将数组接口中的内容设置为信息中的内容。
| handle | 数据矩阵的一个实例 |
| field | 字段名。 |
| 数据 | 用于密集矩阵/向量中值的 JSON 编码array_interface。 |
| int XGDMatrixSetStrFeatureInfo | ( | DMatrixHandle | handle, |
| const char * | field, | ||
| const char ** | features, | ||
| const bst_ulong | size | ||
| ) |
设置所有特征的字符串编码信息。
接受的字段有
| handle | 数据矩阵的一个实例 |
| field | 字段名 |
| features | 指向字符串数组的指针。 |
| size | features 指针的大小(传入的字符串数量)。 |
| int XGDMatrixSetUIntInfo | ( | DMatrixHandle | handle, |
| const char * | field, | ||
| const unsigned * | 数组, | ||
| bst_ulong | 长度 | ||
| ) |
| int XGDMatrixSliceDMatrix | ( | DMatrixHandle | handle, |
| const int * | idxset, | ||
| bst_ulong | 长度, | ||
| DMatrixHandle * | out | ||
| ) |
从现有矩阵的切片内容创建新 dmatrix
| handle | 要切片的 DMatrix 实例 |
| idxset | 索引集 |
| 长度 | 索引集长度 |
| out | 切片后的新矩阵 |
| int XGDMatrixSliceDMatrixEx | ( | DMatrixHandle | handle, |
| const int * | idxset, | ||
| bst_ulong | 长度, | ||
| DMatrixHandle * | out, | ||
| int | allow_groups | ||
| ) |
从现有矩阵的切片内容创建新 dmatrix
| handle | 要切片的 DMatrix 实例 |
| idxset | 索引集 |
| 长度 | 索引集长度 |
| out | 切片后的新矩阵 |
| allow_groups | 允许切片带组的数组 |