xgboost

c_api.h
Go to the documentation of this file.
1
7 #ifndef XGBOOST_C_API_H_
8 #define XGBOOST_C_API_H_
9
10 #ifdef __cplusplus
11 #define XGB_EXTERN_C extern "C"
12 #include <cstdio>
13 #include <cstdint>
14 #else
15 #define XGB_EXTERN_C
16 #include <stdio.h>
17 #include <stdint.h>
18 #endif // __cplusplus
19
20 #if defined(_MSC_VER) || defined(_WIN32)
21 #define XGB_DLL XGB_EXTERN_C __declspec(dllexport)
22 #else
23 #define XGB_DLL XGB_EXTERN_C __attribute__ ((visibility ("default")))
24 #endif // defined(_MSC_VER) || defined(_WIN32)
25
26 // manually define unsigned long
27 typedef uint64_t bst_ulong; // NOLINT(*)
28
30 typedef void *DMatrixHandle; // NOLINT(*)
32 typedef void *BoosterHandle; // NOLINT(*)
33
43 XGB_DLL void XGBoostVersion(int* major, int* minor, int* patch);
44
52 XGB_DLL int XGBuildInfo(char const **out);
53
64 XGB_DLL const char *XGBGetLastError(void);
65
73 XGB_DLL int XGBRegisterLogCallback(void (*callback)(const char*));
74
83 XGB_DLL int XGBSetGlobalConfig(const char* json_str);
84
90 XGB_DLL int XGBGetGlobalConfig(const char** json_str);
91
99 XGB_DLL int XGDMatrixCreateFromFile(const char *fname,
100 int silent,
101 DMatrixHandle *out);
102
114 XGB_DLL int XGDMatrixCreateFromCSREx(const size_t* indptr,
115 const unsigned* indices,
116 const float* data,
117 size_t nindptr,
118 size_t nelem,
119 size_t num_col,
120 DMatrixHandle* out);
121
136 XGB_DLL int XGDMatrixCreateFromCSR(char const *indptr,
137 char const *indices, char const *data,
138 bst_ulong ncol,
139 char const* json_config,
140 DMatrixHandle* out);
141
142
154 XGB_DLL int XGDMatrixCreateFromDense(char const *data,
155 char const *json_config,
156 DMatrixHandle *out);
157
169 XGB_DLL int XGDMatrixCreateFromCSCEx(const size_t* col_ptr,
170 const unsigned* indices,
171 const float* data,
172 size_t nindptr,
173 size_t nelem,
174 size_t num_row,
175 DMatrixHandle* out);
176
186 XGB_DLL int XGDMatrixCreateFromMat(const float *data,
187 bst_ulong nrow,
188 bst_ulong ncol,
189 float missing,
190 DMatrixHandle *out);
201 XGB_DLL int XGDMatrixCreateFromMat_omp(const float *data, // NOLINT
202 bst_ulong nrow, bst_ulong ncol,
203 float missing, DMatrixHandle *out,
204 int nthread);
215 XGB_DLL int XGDMatrixCreateFromDT(void** data,
216 const char ** feature_stypes,
217 bst_ulong nrow,
218 bst_ulong ncol,
219 DMatrixHandle* out,
220 int nthread);
221
233 XGB_DLL int XGDMatrixCreateFromCudaColumnar(char const *data,
234 char const* json_config,
235 DMatrixHandle *out);
236
248 XGB_DLL int XGDMatrixCreateFromCudaArrayInterface(char const *data,
249 char const* json_config,
250 DMatrixHandle *out);
251
293 /* ==== First set of callback functions, used exclusively by JVM packages. ==== */
294
296 typedef void *DataIterHandle; // NOLINT(*)
298 typedef void *DataHolderHandle; // NOLINT(*)
299
300
302 typedef struct { // NOLINT(*)
304 size_t size;
305 /* \brief number of columns in the minibatch. */
306 size_t columns;
308 #ifdef __APPLE__
309 /* Necessary as Java on MacOS defines jlong as long int
310 * and gcc defines int64_t as long long int. */
311 long* offset; // NOLINT(*)
312 #else
313 int64_t* offset; // NOLINT(*)
314 #endif // __APPLE__
315
316 float* label;
318 float* weight;
320 int* index;
322 float* value;
323 } XGBoostBatchCSR;
324
330 XGB_EXTERN_C typedef int XGBCallbackSetData( // NOLINT(*)
331 DataHolderHandle handle, XGBoostBatchCSR batch);
332
344 XGB_EXTERN_C typedef int XGBCallbackDataIterNext( // NOLINT(*)
345 DataIterHandle data_handle, XGBCallbackSetData *set_function,
346 DataHolderHandle set_function_handle);
347
356 XGB_DLL int XGDMatrixCreateFromDataIter(
357 DataIterHandle data_handle,
358 XGBCallbackDataIterNext* callback,
359 const char* cache_info,
360 DMatrixHandle *out);
361
374 XGB_DLL int XGProxyDMatrixCreate(DMatrixHandle* out);
375
383 XGB_EXTERN_C typedef int XGDMatrixCallbackNext(DataIterHandle iter); // NOLINT(*)
384
388 XGB_EXTERN_C typedef void DataIterResetCallback(DataIterHandle handle); // NOLINT(*)
389
390
418 XGB_DLL int XGDMatrixCreateFromCallback(DataIterHandle iter,
419 DMatrixHandle proxy,
420 DataIterResetCallback *reset,
421 XGDMatrixCallbackNext *next,
422 char const* c_json_config,
423 DMatrixHandle *out);
424
449 XGB_DLL int XGDeviceQuantileDMatrixCreateFromCallback(
450 DataIterHandle iter, DMatrixHandle proxy, DataIterResetCallback *reset,
451 XGDMatrixCallbackNext *next, float missing, int nthread, int max_bin,
452 DMatrixHandle *out);
453
463 XGB_DLL int
464 XGProxyDMatrixSetDataCudaArrayInterface(DMatrixHandle handle,
465 const char *c_interface_str);
466
476 XGB_DLL int XGProxyDMatrixSetDataCudaColumnar(DMatrixHandle handle,
477 const char *c_interface_str);
478
488 XGB_DLL int XGProxyDMatrixSetDataDense(DMatrixHandle handle,
489 char const *c_interface_str);
490
501 XGB_DLL int XGProxyDMatrixSetDataCSR(DMatrixHandle handle, char const *indptr,
502 char const *indices, char const *data,
503 bst_ulong ncol);
504
505 /*
506 * ==========================- End data callback APIs ==========================
507 */
508
509
510 XGB_DLL int XGImportArrowRecordBatch(DataIterHandle data_handle, void *ptr_array, void *ptr_schema);
511
526 XGB_DLL int XGDMatrixCreateFromArrowCallback(XGDMatrixCallbackNext *next, char const *json_config,
527 DMatrixHandle *out);
528
537 XGB_DLL int XGDMatrixSliceDMatrix(DMatrixHandle handle,
538 const int *idxset,
539 bst_ulong len,
540 DMatrixHandle *out);
550 XGB_DLL int XGDMatrixSliceDMatrixEx(DMatrixHandle handle,
551 const int *idxset,
552 bst_ulong len,
553 DMatrixHandle *out,
554 int allow_groups);
559 XGB_DLL int XGDMatrixFree(DMatrixHandle handle);
567 XGB_DLL int XGDMatrixSaveBinary(DMatrixHandle handle,
568 const char *fname, int silent);
569
577 XGB_DLL int XGDMatrixSetInfoFromInterface(DMatrixHandle handle,
578 char const* field,
579 char const* c_interface_str);
580
589 XGB_DLL int XGDMatrixSetFloatInfo(DMatrixHandle handle,
590 const char *field,
591 const float *array,
592 bst_ulong len);
601 XGB_DLL int XGDMatrixSetUIntInfo(DMatrixHandle handle,
602 const char *field,
603 const unsigned *array,
604 bst_ulong len);
605
632 XGB_DLL int XGDMatrixSetStrFeatureInfo(DMatrixHandle handle, const char *field,
633 const char **features,
634 const bst_ulong size);
635
671 XGB_DLL int XGDMatrixGetStrFeatureInfo(DMatrixHandle handle, const char *field,
672 bst_ulong *size,
673 const char ***out_features);
674
700 XGB_DLL int XGDMatrixSetDenseInfo(DMatrixHandle handle, const char *field,
701 void const *data, bst_ulong size, int type);
702
710 XGB_DLL int XGDMatrixSetGroup(DMatrixHandle handle,
711 const unsigned *group,
712 bst_ulong len);
713
722 XGB_DLL int XGDMatrixGetFloatInfo(const DMatrixHandle handle,
723 const char *field,
724 bst_ulong* out_len,
725 const float **out_dptr);
734 XGB_DLL int XGDMatrixGetUIntInfo(const DMatrixHandle handle,
735 const char *field,
736 bst_ulong* out_len,
737 const unsigned **out_dptr);
744 XGB_DLL int XGDMatrixNumRow(DMatrixHandle handle,
745 bst_ulong *out);
752 XGB_DLL int XGDMatrixNumCol(DMatrixHandle handle,
753 bst_ulong *out);
754 // --- start XGBoost class
762 XGB_DLL int XGBoosterCreate(const DMatrixHandle dmats[],
763 bst_ulong len,
764 BoosterHandle *out);
770 XGB_DLL int XGBoosterFree(BoosterHandle handle);
771
785 XGB_DLL int XGBoosterSlice(BoosterHandle handle, int begin_layer,
786 int end_layer, int step,
787 BoosterHandle *out);
788
796 XGB_DLL int XGBoosterBoostedRounds(BoosterHandle handle, int* out);
797
805 XGB_DLL int XGBoosterSetParam(BoosterHandle handle,
806 const char *name,
807 const char *value);
808
814 XGB_DLL int XGBoosterGetNumFeature(BoosterHandle handle,
815 bst_ulong *out);
816
824 XGB_DLL int XGBoosterUpdateOneIter(BoosterHandle handle,
825 int iter,
826 DMatrixHandle dtrain);
837 XGB_DLL int XGBoosterBoostOneIter(BoosterHandle handle,
838 DMatrixHandle dtrain,
839 float *grad,
840 float *hess,
841 bst_ulong len);
852 XGB_DLL int XGBoosterEvalOneIter(BoosterHandle handle,
853 int iter,
854 DMatrixHandle dmats[],
855 const char *evnames[],
856 bst_ulong len,
857 const char **out_result);
858
882 XGB_DLL int XGBoosterPredict(BoosterHandle handle,
883 DMatrixHandle dmat,
884 int option_mask,
885 unsigned ntree_limit,
886 int training,
887 bst_ulong *out_len,
888 const float **out_result);
945 XGB_DLL int XGBoosterPredictFromDMatrix(BoosterHandle handle,
946 DMatrixHandle dmat,
947 char const* c_json_config,
948 bst_ulong const **out_shape,
949 bst_ulong *out_dim,
950 float const **out_result);
951 /*
952 * \brief Inplace prediction from CPU dense matrix.
953 *
954 * \param handle Booster handle.
955 * \param values JSON encoded __array_interface__ to values.
956 * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
957 *
958 * Additional fields for inplace prediction are:
959 * "missing": float
960 *
961 * \param m An optional (NULL if not available) proxy DMatrix instance
962 * storing meta info.
963 *
964 * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
965 * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
966 * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
967 *
968 * \return 0 when success, -1 when failure happens
969 */
970 XGB_DLL int XGBoosterPredictFromDense(BoosterHandle handle,
971 char const *values,
972 char const *c_json_config,
973 DMatrixHandle m,
974 bst_ulong const **out_shape,
975 bst_ulong *out_dim,
976 const float **out_result);
977
978 /*
979 * \brief Inplace prediction from CPU CSR matrix.
980 *
981 * \param handle Booster handle.
982 * \param indptr JSON encoded __array_interface__ to row pointer in CSR.
983 * \param indices JSON encoded __array_interface__ to column indices in CSR.
984 * \param values JSON encoded __array_interface__ to values in CSR..
985 * \param ncol Number of features in data.
986 * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
987 * Additional fields for inplace prediction are:
988 * "missing": float
989 *
990 * \param m An optional (NULL if not available) proxy DMatrix instance
991 * storing meta info.
992 *
993 * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
994 * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
995 * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
996 *
997 * \return 0 when success, -1 when failure happens
998 */
999 XGB_DLL int XGBoosterPredictFromCSR(BoosterHandle handle, char const *indptr,
1000 char const *indices, char const *values,
1001 bst_ulong ncol,
1002 char const *c_json_config, DMatrixHandle m,
1003 bst_ulong const **out_shape,
1004 bst_ulong *out_dim,
1005 const float **out_result);
1006
1007 /*
1008 * \brief Inplace prediction from CUDA Dense matrix (cupy in Python).
1009 *
1010 * \param handle Booster handle
1011 * \param values JSON encoded __cuda_array_interface__ to values.
1012 * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
1013 * Additional fields for inplace prediction are:
1014 * "missing": float
1015 *
1016 * \param m An optional (NULL if not available) proxy DMatrix instance
1017 * storing meta info.
1018 * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
1019 * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
1020 * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
1021 *
1022 * \return 0 when success, -1 when failure happens
1023 */
1024 XGB_DLL int XGBoosterPredictFromCudaArray(
1025 BoosterHandle handle, char const *values, char const *c_json_config,
1026 DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim,
1027 const float **out_result);
1028
1029 /*
1030 * \brief Inplace prediction from CUDA dense dataframe (cuDF in Python).
1031 *
1032 * \param handle Booster handle
1033 * \param values List of __cuda_array_interface__ for all columns encoded in JSON list.
1034 * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
1035 * Additional fields for inplace prediction are:
1036 * "missing": float
1037 *
1038 * \param m An optional (NULL if not available) proxy DMatrix instance
1039 * storing meta info.
1040 * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
1041 * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
1042 * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
1043 *
1044 * \return 0 when success, -1 when failure happens
1045 */
1046 XGB_DLL int XGBoosterPredictFromCudaColumnar(
1047 BoosterHandle handle, char const *values, char const *c_json_config,
1048 DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim,
1049 const float **out_result);
1050
1051
1052 /*
1053 * ========================== Begin Serialization APIs =========================
1054 */
1055 /*
1056 * Short note for serialization APIs. There are 3 different sets of serialization API.
1057 *
1058 * - Functions with the term "Model" handles saving/loading XGBoost model like trees or
1059 * linear weights. Striping out parameters configuration like training algorithms or
1060 * CUDA device ID. These functions are designed to let users reuse the trained model
1061 * for different tasks, examples are prediction, training continuation or model
1062 * interpretation.
1063 *
1064 * - Functions with the term "Config" handles save/loading configuration. It helps user
1065 * to study the internal of XGBoost. Also user can use the load method for specifying
1066 * parameters in a structured way. These functions are introduced in 1.0.0, and are not
1067 * yet stable.
1068 *
1069 * - Functions with the term "Serialization" are combined of above two. They are used in
1070 * situations like check-pointing, or continuing training task in distributed
1071 * environment. In these cases the task must be carried out without any user
1072 * intervention.
1073 */
1074
1081 XGB_DLL int XGBoosterLoadModel(BoosterHandle handle,
1082 const char *fname);
1089 XGB_DLL int XGBoosterSaveModel(BoosterHandle handle,
1090 const char *fname);
1098 XGB_DLL int XGBoosterLoadModelFromBuffer(BoosterHandle handle,
1099 const void *buf,
1100 bst_ulong len);
1101
1121 XGB_DLL int XGBoosterSaveModelToBuffer(BoosterHandle handle, char const *json_config,
1122 bst_ulong *out_len, char const **out_dptr);
1123
1127 XGB_DLL int XGBoosterGetModelRaw(BoosterHandle handle, bst_ulong *out_len,
1128 const char **out_dptr);
1129
1139 XGB_DLL int XGBoosterSerializeToBuffer(BoosterHandle handle, bst_ulong *out_len,
1140 const char **out_dptr);
1150 XGB_DLL int XGBoosterUnserializeFromBuffer(BoosterHandle handle,
1151 const void *buf, bst_ulong len);
1152
1160 XGB_DLL int XGBoosterLoadRabitCheckpoint(BoosterHandle handle,
1161 int* version);
1162
1168 XGB_DLL int XGBoosterSaveRabitCheckpoint(BoosterHandle handle);
1169
1170
1183 XGB_DLL int XGBoosterSaveJsonConfig(BoosterHandle handle, bst_ulong *out_len,
1184 char const **out_str);
1194 XGB_DLL int XGBoosterLoadJsonConfig(BoosterHandle handle,
1195 char const *json_parameters);
1196 /*
1197 * =========================== End Serialization APIs ==========================
1198 */
1199
1200
1210 XGB_DLL int XGBoosterDumpModel(BoosterHandle handle,
1211 const char *fmap,
1212 int with_stats,
1213 bst_ulong *out_len,
1214 const char ***out_dump_array);
1215
1226 XGB_DLL int XGBoosterDumpModelEx(BoosterHandle handle,
1227 const char *fmap,
1228 int with_stats,
1229 const char *format,
1230 bst_ulong *out_len,
1231 const char ***out_dump_array);
1232
1244 XGB_DLL int XGBoosterDumpModelWithFeatures(BoosterHandle handle,
1245 int fnum,
1246 const char **fname,
1247 const char **ftype,
1248 int with_stats,
1249 bst_ulong *out_len,
1250 const char ***out_models);
1251
1264 XGB_DLL int XGBoosterDumpModelExWithFeatures(BoosterHandle handle,
1265 int fnum,
1266 const char **fname,
1267 const char **ftype,
1268 int with_stats,
1269 const char *format,
1270 bst_ulong *out_len,
1271 const char ***out_models);
1272
1281 XGB_DLL int XGBoosterGetAttr(BoosterHandle handle,
1282 const char* key,
1283 const char** out,
1284 int *success);
1294 XGB_DLL int XGBoosterSetAttr(BoosterHandle handle,
1295 const char* key,
1296 const char* value);
1304 XGB_DLL int XGBoosterGetAttrNames(BoosterHandle handle,
1305 bst_ulong* out_len,
1306 const char*** out);
1307
1323 XGB_DLL int XGBoosterSetStrFeatureInfo(BoosterHandle handle, const char *field,
1324 const char **features,
1325 const bst_ulong size);
1326
1346 XGB_DLL int XGBoosterGetStrFeatureInfo(BoosterHandle handle, const char *field,
1347 bst_ulong *len,
1348 const char ***out_features);
1349
1375 XGB_DLL int XGBoosterFeatureScore(BoosterHandle handle, const char *json_config,
1376 bst_ulong *out_n_features,
1377 char const ***out_features,
1378 bst_ulong *out_dim,
1379 bst_ulong const **out_shape,
1380 float const **out_scores);
1381 #endif // XGBOOST_C_API_H_
XGBoosterPredictFromDense
XGB_DLL int XGBoosterPredictFromDense(BoosterHandle handle, char const *values, char const *c_json_config, DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
XGBoosterLoadRabitCheckpoint
XGB_DLL int XGBoosterLoadRabitCheckpoint(BoosterHandle handle, int *version)
Initialize the booster from rabit checkpoint. This is used in distributed training API.
XGDMatrixCreateFromDT
XGB_DLL int XGDMatrixCreateFromDT(void **data, const char **feature_stypes, bst_ulong nrow, bst_ulong ncol, DMatrixHandle *out, int nthread)
create matrix content from python data table
XGBoosterLoadJsonConfig
XGB_DLL int XGBoosterLoadJsonConfig(BoosterHandle handle, char const *json_parameters)
Load XGBoost's internal configuration from a JSON document. Currently the support is experimental,...
XGBSetGlobalConfig
XGB_DLL int XGBSetGlobalConfig(const char *json_str)
Set global configuration (collection of parameters that apply globally). This function accepts the li...
XGImportArrowRecordBatch
XGB_DLL int XGImportArrowRecordBatch(DataIterHandle data_handle, void *ptr_array, void *ptr_schema)
XGDMatrixCreateFromCudaArrayInterface
XGB_DLL int XGDMatrixCreateFromCudaArrayInterface(char const *data, char const *json_config, DMatrixHandle *out)
Create DMatrix from CUDA array.
XGDMatrixCreateFromFile
XGB_DLL int XGDMatrixCreateFromFile(const char *fname, int silent, DMatrixHandle *out)
load a data matrix
XGBCallbackSetData
XGB_EXTERN_C typedef int XGBCallbackSetData(DataHolderHandle handle, XGBoostBatchCSR batch)
Callback to set the data to handle,.
XGB_EXTERN_C
#define XGB_EXTERN_C
Definition: c_api.h:15
XGBRegisterLogCallback
XGB_DLL int XGBRegisterLogCallback(void(*callback)(const char *))
register callback function for LOG(INFO) messages – helpful messages that are not errors....
XGBoosterUnserializeFromBuffer
XGB_DLL int XGBoosterUnserializeFromBuffer(BoosterHandle handle, const void *buf, bst_ulong len)
Memory snapshot based serialization method. Loads the buffer returned from ‘XGBoosterSerializeToBuffe...
XGBoosterPredict
XGB_DLL int XGBoosterPredict(BoosterHandle handle, DMatrixHandle dmat, int option_mask, unsigned ntree_limit, int training, bst_ulong *out_len, const float **out_result)
make prediction based on dmat (deprecated, use XGBoosterPredictFromDMatrix instead)
XGBoosterBoostedRounds
XGB_DLL int XGBoosterBoostedRounds(BoosterHandle handle, int *out)
Get number of boosted rounds from gradient booster. When process_type is update, this number might dr...
XGProxyDMatrixSetDataCudaArrayInterface
XGB_DLL int XGProxyDMatrixSetDataCudaArrayInterface(DMatrixHandle handle, const char *c_interface_str)
Set data on a DMatrix proxy.
XGDMatrixCreateFromCallback
XGB_DLL int XGDMatrixCreateFromCallback(DataIterHandle iter, DMatrixHandle proxy, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, char const *c_json_config, DMatrixHandle *out)
Create an external memory DMatrix with data iterator.
XGDMatrixNumCol
XGB_DLL int XGDMatrixNumCol(DMatrixHandle handle, bst_ulong *out)
get number of columns
XGDMatrixCreateFromCSCEx
XGB_DLL int XGDMatrixCreateFromCSCEx(const size_t *col_ptr, const unsigned *indices, const float *data, size_t nindptr, size_t nelem, size_t num_row, DMatrixHandle *out)
create a matrix content from CSC format
XGDMatrixSliceDMatrixEx
XGB_DLL int XGDMatrixSliceDMatrixEx(DMatrixHandle handle, const int *idxset, bst_ulong len, DMatrixHandle *out, int allow_groups)
create a new dmatrix from sliced content of existing matrix
XGBoostBatchCSR::index
int * index
feature index
Definition: c_api.h:320
XGDMatrixSetInfoFromInterface
XGB_DLL int XGDMatrixSetInfoFromInterface(DMatrixHandle handle, char const *field, char const *c_interface_str)
Set content in array interface to a content in info.
XGBoosterSaveModel
XGB_DLL int XGBoosterSaveModel(BoosterHandle handle, const char *fname)
Save model into existing file.
XGProxyDMatrixSetDataCudaColumnar
XGB_DLL int XGProxyDMatrixSetDataCudaColumnar(DMatrixHandle handle, const char *c_interface_str)
Set data on a DMatrix proxy.
XGDeviceQuantileDMatrixCreateFromCallback
XGB_DLL int XGDeviceQuantileDMatrixCreateFromCallback(DataIterHandle iter, DMatrixHandle proxy, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, float missing, int nthread, int max_bin, DMatrixHandle *out)
Create a Quantile DMatrix with data iterator.
XGBoostBatchCSR
Mini batch used in XGBoost Data Iteration.
Definition: c_api.h:302
XGDMatrixSaveBinary
XGB_DLL int XGDMatrixSaveBinary(DMatrixHandle handle, const char *fname, int silent)
load a data matrix into binary file
XGProxyDMatrixSetDataDense
XGB_DLL int XGProxyDMatrixSetDataDense(DMatrixHandle handle, char const *c_interface_str)
Set data on a DMatrix proxy.
XGBoosterPredictFromDMatrix
XGB_DLL int XGBoosterPredictFromDMatrix(BoosterHandle handle, DMatrixHandle dmat, char const *c_json_config, bst_ulong const **out_shape, bst_ulong *out_dim, float const **out_result)
Make prediction from DMatrix, replacing XGBoosterPredict.
XGDMatrixSliceDMatrix
XGB_DLL int XGDMatrixSliceDMatrix(DMatrixHandle handle, const int *idxset, bst_ulong len, DMatrixHandle *out)
create a new dmatrix from sliced content of existing matrix
XGBoosterSaveModelToBuffer
XGB_DLL int XGBoosterSaveModelToBuffer(BoosterHandle handle, char const *json_config, bst_ulong *out_len, char const **out_dptr)
Save model into raw bytes, return header of the array. User must copy the result out,...
XGBoostBatchCSR::size
size_t size
number of rows in the minibatch
Definition: c_api.h:304
XGBoosterSetParam
XGB_DLL int XGBoosterSetParam(BoosterHandle handle, const char *name, const char *value)
set parameters
XGBoostBatchCSR::value
float * value
feature values
Definition: c_api.h:322
XGBGetLastError
const XGB_DLL char * XGBGetLastError(void)
get string message of the last error
DataIterHandle
void * DataIterHandle
handle to a external data iterator
Definition: c_api.h:296
XGBoosterFeatureScore
XGB_DLL int XGBoosterFeatureScore(BoosterHandle handle, const char *json_config, bst_ulong *out_n_features, char const ***out_features, bst_ulong *out_dim, bst_ulong const **out_shape, float const **out_scores)
Calculate feature scores for tree models. When used on linear model, only the weight importance type ...
XGDMatrixCreateFromMat_omp
XGB_DLL int XGDMatrixCreateFromMat_omp(const float *data, bst_ulong nrow, bst_ulong ncol, float missing, DMatrixHandle *out, int nthread)
create matrix content from dense matrix
XGBoosterDumpModelEx
XGB_DLL int XGBoosterDumpModelEx(BoosterHandle handle, const char *fmap, int with_stats, const char *format, bst_ulong *out_len, const char ***out_dump_array)
dump model, return array of strings representing model dump
XGBoosterDumpModel
XGB_DLL int XGBoosterDumpModel(BoosterHandle handle, const char *fmap, int with_stats, bst_ulong *out_len, const char ***out_dump_array)
dump model, return array of strings representing model dump
XGBoosterPredictFromCudaColumnar
XGB_DLL int XGBoosterPredictFromCudaColumnar(BoosterHandle handle, char const *values, char const *c_json_config, DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
XGDMatrixCallbackNext
XGB_EXTERN_C typedef int XGDMatrixCallbackNext(DataIterHandle iter)
Callback function prototype for getting next batch of data.
XGBoostBatchCSR::label
float * label
labels of each instance
Definition: c_api.h:316
XGB_DLL
#define XGB_DLL
Definition: c_api.h:23
XGDMatrixGetFloatInfo
XGB_DLL int XGDMatrixGetFloatInfo(const DMatrixHandle handle, const char *field, bst_ulong *out_len, const float **out_dptr)
get float info vector from matrix.
XGBoosterFree
XGB_DLL int XGBoosterFree(BoosterHandle handle)
free obj in handle
XGBoosterGetNumFeature
XGB_DLL int XGBoosterGetNumFeature(BoosterHandle handle, bst_ulong *out)
get number of features
XGDMatrixSetUIntInfo
XGB_DLL int XGDMatrixSetUIntInfo(DMatrixHandle handle, const char *field, const unsigned *array, bst_ulong len)
set uint32 vector to a content in info
DataIterResetCallback
XGB_EXTERN_C typedef void DataIterResetCallback(DataIterHandle handle)
Callback function prototype for resetting external iterator.
XGBoostVersion
XGB_DLL void XGBoostVersion(int *major, int *minor, int *patch)
Return the version of the XGBoost library being currently used.
XGDMatrixNumRow
XGB_DLL int XGDMatrixNumRow(DMatrixHandle handle, bst_ulong *out)
get number of rows.
XGBoosterPredictFromCSR
XGB_DLL int XGBoosterPredictFromCSR(BoosterHandle handle, char const *indptr, char const *indices, char const *values, bst_ulong ncol, char const *c_json_config, DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
XGBoosterLoadModelFromBuffer
XGB_DLL int XGBoosterLoadModelFromBuffer(BoosterHandle handle, const void *buf, bst_ulong len)
load model from in memory buffer
XGBoosterDumpModelWithFeatures
XGB_DLL int XGBoosterDumpModelWithFeatures(BoosterHandle handle, int fnum, const char **fname, const char **ftype, int with_stats, bst_ulong *out_len, const char ***out_models)
dump model, return array of strings representing model dump
DataHolderHandle
void * DataHolderHandle
handle to a internal data holder.
Definition: c_api.h:298
XGBCallbackDataIterNext
XGB_EXTERN_C typedef int XGBCallbackDataIterNext(DataIterHandle data_handle, XGBCallbackSetData *set_function, DataHolderHandle set_function_handle)
The data reading callback function. The iterator will be able to give subset of batch in the data.
XGBoosterSetStrFeatureInfo
XGB_DLL int XGBoosterSetStrFeatureInfo(BoosterHandle handle, const char *field, const char **features, const bst_ulong size)
Set string encoded feature info in Booster, similar to the feature info in DMatrix.
XGBoostBatchCSR::columns
size_t columns
Definition: c_api.h:306
XGDMatrixSetGroup
XGB_DLL int XGDMatrixSetGroup(DMatrixHandle handle, const unsigned *group, bst_ulong len)
(deprecated) Use XGDMatrixSetUIntInfo instead. Set group of the training matrix
XGBoosterSaveRabitCheckpoint
XGB_DLL int XGBoosterSaveRabitCheckpoint(BoosterHandle handle)
Save the current checkpoint to rabit.
XGDMatrixSetDenseInfo
XGB_DLL int XGDMatrixSetDenseInfo(DMatrixHandle handle, const char *field, void const *data, bst_ulong size, int type)
Set meta info from dense matrix. Valid field names are:
XGDMatrixSetStrFeatureInfo
XGB_DLL int XGDMatrixSetStrFeatureInfo(DMatrixHandle handle, const char *field, const char **features, const bst_ulong size)
Set string encoded information of all features.
XGBoosterGetAttrNames
XGB_DLL int XGBoosterGetAttrNames(BoosterHandle handle, bst_ulong *out_len, const char ***out)
Get the names of all attribute from Booster.
XGDMatrixCreateFromDense
XGB_DLL int XGDMatrixCreateFromDense(char const *data, char const *json_config, DMatrixHandle *out)
Create a matrix from dense array.
XGDMatrixSetFloatInfo
XGB_DLL int XGDMatrixSetFloatInfo(DMatrixHandle handle, const char *field, const float *array, bst_ulong len)
set float vector to a content in info
XGBoosterPredictFromCudaArray
XGB_DLL int XGBoosterPredictFromCudaArray(BoosterHandle handle, char const *values, char const *c_json_config, DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
XGBoosterGetModelRaw
XGB_DLL int XGBoosterGetModelRaw(BoosterHandle handle, bst_ulong *out_len, const char **out_dptr)
Deprecated, use XGBoosterSaveModelToBuffer instead.
XGBoostBatchCSR::offset
int64_t * offset
row pointer to the rows in the data
Definition: c_api.h:313
XGBoosterGetStrFeatureInfo
XGB_DLL int XGBoosterGetStrFeatureInfo(BoosterHandle handle, const char *field, bst_ulong *len, const char ***out_features)
Get string encoded feature info from Booster, similar to feature info in DMatrix.
XGBoosterLoadModel
XGB_DLL int XGBoosterLoadModel(BoosterHandle handle, const char *fname)
Load model from existing file.
XGDMatrixCreateFromCSR
XGB_DLL int XGDMatrixCreateFromCSR(char const *indptr, char const *indices, char const *data, bst_ulong ncol, char const *json_config, DMatrixHandle *out)
Create a matrix from CSR matrix.
XGBoosterBoostOneIter
XGB_DLL int XGBoosterBoostOneIter(BoosterHandle handle, DMatrixHandle dtrain, float *grad, float *hess, bst_ulong len)
update the model, by directly specify gradient and second order gradient, this can be used to replace...
XGBoosterGetAttr
XGB_DLL int XGBoosterGetAttr(BoosterHandle handle, const char *key, const char **out, int *success)
Get string attribute from Booster.
XGDMatrixCreateFromCudaColumnar
XGB_DLL int XGDMatrixCreateFromCudaColumnar(char const *data, char const *json_config, DMatrixHandle *out)
Create DMatrix from CUDA columnar format. (cuDF)
XGBoostBatchCSR::weight
float * weight
weight of each instance, can be NULL
Definition: c_api.h:318
XGBGetGlobalConfig
XGB_DLL int XGBGetGlobalConfig(const char **json_str)
Get current global configuration (collection of parameters that apply globally).
XGBoosterUpdateOneIter
XGB_DLL int XGBoosterUpdateOneIter(BoosterHandle handle, int iter, DMatrixHandle dtrain)
update the model in one round using dtrain
DMatrixHandle
void * DMatrixHandle
handle to DMatrix
Definition: c_api.h:30
BoosterHandle
void * BoosterHandle
handle to Booster
Definition: c_api.h:32
XGBuildInfo
XGB_DLL int XGBuildInfo(char const **out)
Get compile information of shared library.
XGBoosterSaveJsonConfig
XGB_DLL int XGBoosterSaveJsonConfig(BoosterHandle handle, bst_ulong *out_len, char const **out_str)
Save XGBoost's internal configuration into a JSON document. Currently the support is experimental,...
XGDMatrixCreateFromCSREx
XGB_DLL int XGDMatrixCreateFromCSREx(const size_t *indptr, const unsigned *indices, const float *data, size_t nindptr, size_t nelem, size_t num_col, DMatrixHandle *out)
create a matrix content from CSR format
XGBoosterSetAttr
XGB_DLL int XGBoosterSetAttr(BoosterHandle handle, const char *key, const char *value)
Set or delete string attribute.
XGProxyDMatrixSetDataCSR
XGB_DLL int XGProxyDMatrixSetDataCSR(DMatrixHandle handle, char const *indptr, char const *indices, char const *data, bst_ulong ncol)
Set data on a DMatrix proxy.
XGBoosterEvalOneIter
XGB_DLL int XGBoosterEvalOneIter(BoosterHandle handle, int iter, DMatrixHandle dmats[], const char *evnames[], bst_ulong len, const char **out_result)
get evaluation statistics for xgboost
XGDMatrixCreateFromDataIter
XGB_DLL int XGDMatrixCreateFromDataIter(DataIterHandle data_handle, XGBCallbackDataIterNext *callback, const char *cache_info, DMatrixHandle *out)
Create a DMatrix from a data iterator.
bst_ulong
uint64_t bst_ulong
Definition: c_api.h:27
XGProxyDMatrixCreate
XGB_DLL int XGProxyDMatrixCreate(DMatrixHandle *out)
Create a DMatrix proxy for setting data, can be free by XGDMatrixFree.
XGDMatrixGetUIntInfo
XGB_DLL int XGDMatrixGetUIntInfo(const DMatrixHandle handle, const char *field, bst_ulong *out_len, const unsigned **out_dptr)
get uint32 info vector from matrix
XGBoosterSlice
XGB_DLL int XGBoosterSlice(BoosterHandle handle, int begin_layer, int end_layer, int step, BoosterHandle *out)
Slice a model using boosting index. The slice m:n indicates taking all trees that were fit during the...
XGDMatrixFree
XGB_DLL int XGDMatrixFree(DMatrixHandle handle)
free space in data matrix
XGDMatrixCreateFromArrowCallback
XGB_DLL int XGDMatrixCreateFromArrowCallback(XGDMatrixCallbackNext *next, char const *json_config, DMatrixHandle *out)
Construct DMatrix from arrow using callbacks. Arrow related C API is not stable and subject to change...
XGBoosterSerializeToBuffer
XGB_DLL int XGBoosterSerializeToBuffer(BoosterHandle handle, bst_ulong *out_len, const char **out_dptr)
Memory snapshot based serialization method. Saves everything states into buffer.
XGDMatrixGetStrFeatureInfo
XGB_DLL int XGDMatrixGetStrFeatureInfo(DMatrixHandle handle, const char *field, bst_ulong *size, const char ***out_features)
Get string encoded information of all features.
XGDMatrixCreateFromMat
XGB_DLL int XGDMatrixCreateFromMat(const float *data, bst_ulong nrow, bst_ulong ncol, float missing, DMatrixHandle *out)
create matrix content from dense matrix
XGBoosterDumpModelExWithFeatures
XGB_DLL 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)
dump model, return array of strings representing model dump
XGBoosterCreate
XGB_DLL int XGBoosterCreate(const DMatrixHandle dmats[], bst_ulong len, BoosterHandle *out)
create xgboost learner