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 
55 XGB_DLL const char *XGBGetLastError(void);
56 
64 XGB_DLL int XGBRegisterLogCallback(void (*callback)(const char*));
65 
74 XGB_DLL int XGBSetGlobalConfig(const char* json_str);
75 
81 XGB_DLL int XGBGetGlobalConfig(const char** json_str);
82 
90 XGB_DLL int XGDMatrixCreateFromFile(const char *fname,
91  int silent,
92  DMatrixHandle *out);
93 
105 XGB_DLL int XGDMatrixCreateFromCSREx(const size_t* indptr,
106  const unsigned* indices,
107  const float* data,
108  size_t nindptr,
109  size_t nelem,
110  size_t num_col,
111  DMatrixHandle* out);
112 
127 XGB_DLL int XGDMatrixCreateFromCSR(char const *indptr,
128  char const *indices, char const *data,
129  bst_ulong ncol,
130  char const* json_config,
131  DMatrixHandle* out);
132 
133 
145 XGB_DLL int XGDMatrixCreateFromDense(char const *data,
146  char const *json_config,
147  DMatrixHandle *out);
148 
160 XGB_DLL int XGDMatrixCreateFromCSCEx(const size_t* col_ptr,
161  const unsigned* indices,
162  const float* data,
163  size_t nindptr,
164  size_t nelem,
165  size_t num_row,
166  DMatrixHandle* out);
167 
177 XGB_DLL int XGDMatrixCreateFromMat(const float *data,
178  bst_ulong nrow,
179  bst_ulong ncol,
180  float missing,
181  DMatrixHandle *out);
192 XGB_DLL int XGDMatrixCreateFromMat_omp(const float *data, // NOLINT
193  bst_ulong nrow, bst_ulong ncol,
194  float missing, DMatrixHandle *out,
195  int nthread);
206 XGB_DLL int XGDMatrixCreateFromDT(void** data,
207  const char ** feature_stypes,
208  bst_ulong nrow,
209  bst_ulong ncol,
210  DMatrixHandle* out,
211  int nthread);
212 
224 XGB_DLL int XGDMatrixCreateFromCudaColumnar(char const *data,
225  char const* json_config,
226  DMatrixHandle *out);
227 
240  char const* json_config,
241  DMatrixHandle *out);
242 
243 /*
244  * ========================== Begin data callback APIs =========================
245  *
246  * Short notes for data callback
247  *
248  * There are 2 sets of data callbacks for DMatrix. The first one is currently exclusively
249  * used by JVM packages. It uses `XGBoostBatchCSR` to accept batches for CSR formated
250  * input, and concatenate them into 1 final big CSR. The related functions are:
251  *
252  * - XGBCallbackSetData
253  * - XGBCallbackDataIterNext
254  * - XGDMatrixCreateFromDataIter
255  *
256  * Another set is used by external data iterator. It accept foreign data iterators as
257  * callbacks. There are 2 different senarios where users might want to pass in callbacks
258  * instead of raw data. First it's the Quantile DMatrix used by GPU Hist. For this case,
259  * the data is first compressed by quantile sketching then merged. This is particular
260  * useful for distributed setting as it eliminates 2 copies of data. 1 by a `concat` from
261  * external library to make the data into a blob for normal DMatrix initialization,
262  * another by the internal CSR copy of DMatrix. The second use case is external memory
263  * support where users can pass a custom data iterator into XGBoost for loading data in
264  * batches. There are short notes on each of the use case in respected DMatrix factory
265  * function.
266  *
267  * Related functions are:
268  *
269  * # Factory functions
270  * - `XGDMatrixCreateFromCallback` for external memory
271  * - `XGDeviceQuantileDMatrixCreateFromCallback` for quantile DMatrix
272  *
273  * # Proxy that callers can use to pass data to XGBoost
274  * - XGProxyDMatrixCreate
275  * - XGDMatrixCallbackNext
276  * - DataIterResetCallback
277  * - XGProxyDMatrixSetDataCudaArrayInterface
278  * - XGProxyDMatrixSetDataCudaColumnar
279  * - XGProxyDMatrixSetDataDense
280  * - XGProxyDMatrixSetDataCSR
281  * - ... (data setters)
282  */
283 
284 /* ==== First set of callback functions, used exclusively by JVM packages. ==== */
285 
287 typedef void *DataIterHandle; // NOLINT(*)
289 typedef void *DataHolderHandle; // NOLINT(*)
290 
291 
293 typedef struct { // NOLINT(*)
295  size_t size;
296  /* \brief number of columns in the minibatch. */
297  size_t columns;
299 #ifdef __APPLE__
300  /* Necessary as Java on MacOS defines jlong as long int
301  * and gcc defines int64_t as long long int. */
302  long* offset; // NOLINT(*)
303 #else
304  int64_t* offset; // NOLINT(*)
305 #endif // __APPLE__
306 
307  float* label;
309  float* weight;
311  int* index;
313  float* value;
315 
321 XGB_EXTERN_C typedef int XGBCallbackSetData( // NOLINT(*)
322  DataHolderHandle handle, XGBoostBatchCSR batch);
323 
335 XGB_EXTERN_C typedef int XGBCallbackDataIterNext( // NOLINT(*)
336  DataIterHandle data_handle, XGBCallbackSetData *set_function,
337  DataHolderHandle set_function_handle);
338 
348  DataIterHandle data_handle,
349  XGBCallbackDataIterNext* callback,
350  const char* cache_info,
351  DMatrixHandle *out);
352 
366 
374 XGB_EXTERN_C typedef int XGDMatrixCallbackNext(DataIterHandle iter); // NOLINT(*)
375 
379 XGB_EXTERN_C typedef void DataIterResetCallback(DataIterHandle handle); // NOLINT(*)
380 
381 
410  DMatrixHandle proxy,
411  DataIterResetCallback *reset,
412  XGDMatrixCallbackNext *next,
413  char const* c_json_config,
414  DMatrixHandle *out);
415 
442  XGDMatrixCallbackNext *next, float missing, int nthread, int max_bin,
443  DMatrixHandle *out);
444 
454 XGB_DLL int
456  const char *c_interface_str);
457 
468  const char *c_interface_str);
469 
480  char const *c_interface_str);
481 
492 XGB_DLL int XGProxyDMatrixSetDataCSR(DMatrixHandle handle, char const *indptr,
493  char const *indices, char const *data,
494  bst_ulong ncol);
495 
496 
497 /*
498  * ==========================- End data callback APIs ==========================
499  */
500 
501 
502 
512  const int *idxset,
513  bst_ulong len,
514  DMatrixHandle *out);
525  const int *idxset,
526  bst_ulong len,
527  DMatrixHandle *out,
528  int allow_groups);
542  const char *fname, int silent);
543 
552  char const* field,
553  char const* c_interface_str);
554 
564  const char *field,
565  const float *array,
566  bst_ulong len);
576  const char *field,
577  const unsigned *array,
578  bst_ulong len);
579 
605 XGB_DLL int XGDMatrixSetStrFeatureInfo(DMatrixHandle handle, const char *field,
606  const char **features,
607  const bst_ulong size);
608 
644 XGB_DLL int XGDMatrixGetStrFeatureInfo(DMatrixHandle handle, const char *field,
645  bst_ulong *size,
646  const char ***out_features);
647 
673 XGB_DLL int XGDMatrixSetDenseInfo(DMatrixHandle handle, const char *field,
674  void const *data, bst_ulong size, int type);
675 
684  const unsigned *group,
685  bst_ulong len);
686 
696  const char *field,
697  bst_ulong* out_len,
698  const float **out_dptr);
708  const char *field,
709  bst_ulong* out_len,
710  const unsigned **out_dptr);
718  bst_ulong *out);
726  bst_ulong *out);
727 // --- start XGBoost class
735 XGB_DLL int XGBoosterCreate(const DMatrixHandle dmats[],
736  bst_ulong len,
737  BoosterHandle *out);
744 
758 XGB_DLL int XGBoosterSlice(BoosterHandle handle, int begin_layer,
759  int end_layer, int step,
760  BoosterHandle *out);
761 
769 XGB_DLL int XGBoosterBoostedRounds(BoosterHandle handle, int* out);
770 
779  const char *name,
780  const char *value);
781 
788  bst_ulong *out);
789 
798  int iter,
799  DMatrixHandle dtrain);
811  DMatrixHandle dtrain,
812  float *grad,
813  float *hess,
814  bst_ulong len);
826  int iter,
827  DMatrixHandle dmats[],
828  const char *evnames[],
829  bst_ulong len,
830  const char **out_result);
831 
856  DMatrixHandle dmat,
857  int option_mask,
858  unsigned ntree_limit,
859  int training,
860  bst_ulong *out_len,
861  const float **out_result);
919  DMatrixHandle dmat,
920  char const* c_json_config,
921  bst_ulong const **out_shape,
922  bst_ulong *out_dim,
923  float const **out_result);
924 /*
925  * \brief Inplace prediction from CPU dense matrix.
926  *
927  * \param handle Booster handle.
928  * \param values JSON encoded __array_interface__ to values.
929  * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
930  *
931  * Additional fields for inplace prediction are:
932  * "missing": float
933  *
934  * \param m An optional (NULL if not available) proxy DMatrix instance
935  * storing meta info.
936  *
937  * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
938  * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
939  * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
940  *
941  * \return 0 when success, -1 when failure happens
942  */
944  char const *values,
945  char const *c_json_config,
946  DMatrixHandle m,
947  bst_ulong const **out_shape,
948  bst_ulong *out_dim,
949  const float **out_result);
950 
951 /*
952  * \brief Inplace prediction from CPU CSR matrix.
953  *
954  * \param handle Booster handle.
955  * \param indptr JSON encoded __array_interface__ to row pointer in CSR.
956  * \param indices JSON encoded __array_interface__ to column indices in CSR.
957  * \param values JSON encoded __array_interface__ to values in CSR..
958  * \param ncol Number of features in data.
959  * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
960  * Additional fields for inplace prediction are:
961  * "missing": float
962  *
963  * \param m An optional (NULL if not available) proxy DMatrix instance
964  * storing meta info.
965  *
966  * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
967  * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
968  * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
969  *
970  * \return 0 when success, -1 when failure happens
971  */
972 XGB_DLL int XGBoosterPredictFromCSR(BoosterHandle handle, char const *indptr,
973  char const *indices, char const *values,
974  bst_ulong ncol,
975  char const *c_json_config, DMatrixHandle m,
976  bst_ulong const **out_shape,
977  bst_ulong *out_dim,
978  const float **out_result);
979 
980 /*
981  * \brief Inplace prediction from CUDA Dense matrix (cupy in Python).
982  *
983  * \param handle Booster handle
984  * \param values JSON encoded __cuda_array_interface__ to values.
985  * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
986  * Additional fields for inplace prediction are:
987  * "missing": float
988  *
989  * \param m An optional (NULL if not available) proxy DMatrix instance
990  * storing meta info.
991  * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
992  * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
993  * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
994  *
995  * \return 0 when success, -1 when failure happens
996  */
998  BoosterHandle handle, char const *values, char const *c_json_config,
999  DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim,
1000  const float **out_result);
1001 
1002 /*
1003  * \brief Inplace prediction from CUDA dense dataframe (cuDF in Python).
1004  *
1005  * \param handle Booster handle
1006  * \param values List of __cuda_array_interface__ for all columns encoded in JSON list.
1007  * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
1008  * Additional fields for inplace prediction are:
1009  * "missing": float
1010  *
1011  * \param m An optional (NULL if not available) proxy DMatrix instance
1012  * storing meta info.
1013  * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
1014  * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
1015  * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
1016  *
1017  * \return 0 when success, -1 when failure happens
1018  */
1020  BoosterHandle handle, char const *values, char const *c_json_config,
1021  DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim,
1022  const float **out_result);
1023 
1024 
1025 /*
1026  * ========================== Begin Serialization APIs =========================
1027  */
1028 /*
1029  * Short note for serialization APIs. There are 3 different sets of serialization API.
1030  *
1031  * - Functions with the term "Model" handles saving/loading XGBoost model like trees or
1032  * linear weights. Striping out parameters configuration like training algorithms or
1033  * CUDA device ID. These functions are designed to let users reuse the trained model
1034  * for different tasks, examples are prediction, training continuation or model
1035  * interpretation.
1036  *
1037  * - Functions with the term "Config" handles save/loading configuration. It helps user
1038  * to study the internal of XGBoost. Also user can use the load method for specifying
1039  * parameters in a structured way. These functions are introduced in 1.0.0, and are not
1040  * yet stable.
1041  *
1042  * - Functions with the term "Serialization" are combined of above two. They are used in
1043  * situations like check-pointing, or continuing training task in distributed
1044  * environment. In these cases the task must be carried out without any user
1045  * intervention.
1046  */
1047 
1055  const char *fname);
1063  const char *fname);
1072  const void *buf,
1073  bst_ulong len);
1083  const char **out_dptr);
1084 
1095  const char **out_dptr);
1106  const void *buf, bst_ulong len);
1107 
1116  int* version);
1117 
1124 
1125 
1139  char const **out_str);
1150  char const *json_parameters);
1151 /*
1152  * =========================== End Serialization APIs ==========================
1153  */
1154 
1155 
1166  const char *fmap,
1167  int with_stats,
1168  bst_ulong *out_len,
1169  const char ***out_dump_array);
1170 
1182  const char *fmap,
1183  int with_stats,
1184  const char *format,
1185  bst_ulong *out_len,
1186  const char ***out_dump_array);
1187 
1200  int fnum,
1201  const char **fname,
1202  const char **ftype,
1203  int with_stats,
1204  bst_ulong *out_len,
1205  const char ***out_models);
1206 
1220  int fnum,
1221  const char **fname,
1222  const char **ftype,
1223  int with_stats,
1224  const char *format,
1225  bst_ulong *out_len,
1226  const char ***out_models);
1227 
1237  const char* key,
1238  const char** out,
1239  int *success);
1250  const char* key,
1251  const char* value);
1260  bst_ulong* out_len,
1261  const char*** out);
1262 
1278 XGB_DLL int XGBoosterSetStrFeatureInfo(BoosterHandle handle, const char *field,
1279  const char **features,
1280  const bst_ulong size);
1281 
1301 XGB_DLL int XGBoosterGetStrFeatureInfo(BoosterHandle handle, const char *field,
1302  bst_ulong *len,
1303  const char ***out_features);
1304 
1330 XGB_DLL int XGBoosterFeatureScore(BoosterHandle handle, const char *json_config,
1331  bst_ulong *out_n_features,
1332  char const ***out_features,
1333  bst_ulong *out_dim,
1334  bst_ulong const **out_shape,
1335  float const **out_scores);
1336 #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...
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:311
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:293
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
XGBoostBatchCSR::size
size_t size
number of rows in the minibatch
Definition: c_api.h:295
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:313
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:287
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:307
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:289
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:297
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)
save model into binary raw bytes, return header of the array user must copy the result out,...
XGBoostBatchCSR::offset
int64_t * offset
row pointer to the rows in the data
Definition: c_api.h:304
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:309
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
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
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