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 
144 XGB_DLL int XGDMatrixCreateFromCSCEx(const size_t* col_ptr,
145  const unsigned* indices,
146  const float* data,
147  size_t nindptr,
148  size_t nelem,
149  size_t num_row,
150  DMatrixHandle* out);
151 
161 XGB_DLL int XGDMatrixCreateFromMat(const float *data,
162  bst_ulong nrow,
163  bst_ulong ncol,
164  float missing,
165  DMatrixHandle *out);
176 XGB_DLL int XGDMatrixCreateFromMat_omp(const float *data, // NOLINT
177  bst_ulong nrow, bst_ulong ncol,
178  float missing, DMatrixHandle *out,
179  int nthread);
190 XGB_DLL int XGDMatrixCreateFromDT(void** data,
191  const char ** feature_stypes,
192  bst_ulong nrow,
193  bst_ulong ncol,
194  DMatrixHandle* out,
195  int nthread);
196 
197 /*
198  * ========================== Begin data callback APIs =========================
199  *
200  * Short notes for data callback
201  *
202  * There are 2 sets of data callbacks for DMatrix. The first one is currently exclusively
203  * used by JVM packages. It uses `XGBoostBatchCSR` to accept batches for CSR formated
204  * input, and concatenate them into 1 final big CSR. The related functions are:
205  *
206  * - XGBCallbackSetData
207  * - XGBCallbackDataIterNext
208  * - XGDMatrixCreateFromDataIter
209  *
210  * Another set is used by Quantile based DMatrix (used by hist algorithm) for reducing
211  * memory usage. Currently only GPU implementation is available. It accept foreign data
212  * iterators as callbacks and works similar to external memory. For GPU Hist, the data is
213  * first compressed by quantile sketching then merged. This is particular useful for
214  * distributed setting as it eliminates 2 copies of data. 1 by a `concat` from external
215  * library to make the data into a blob for normal DMatrix initialization, another by the
216  * internal CSR copy of DMatrix. Related functions are:
217  *
218  * - XGProxyDMatrixCreate
219  * - XGDMatrixCallbackNext
220  * - DataIterResetCallback
221  * - XGDeviceQuantileDMatrixSetDataCudaArrayInterface
222  * - XGDeviceQuantileDMatrixSetDataCudaColumnar
223  * - ... (data setters)
224  */
225 
226 /* ==== First set of callback functions, used exclusively by JVM packages. ==== */
227 
229 typedef void *DataIterHandle; // NOLINT(*)
231 typedef void *DataHolderHandle; // NOLINT(*)
232 
233 
235 typedef struct { // NOLINT(*)
237  size_t size;
238  /* \brief number of columns in the minibatch. */
239  size_t columns;
241 #ifdef __APPLE__
242  /* Necessary as Java on MacOS defines jlong as long int
243  * and gcc defines int64_t as long long int. */
244  long* offset; // NOLINT(*)
245 #else
246  int64_t* offset; // NOLINT(*)
247 #endif // __APPLE__
248 
249  float* label;
251  float* weight;
253  int* index;
255  float* value;
257 
263 XGB_EXTERN_C typedef int XGBCallbackSetData( // NOLINT(*)
264  DataHolderHandle handle, XGBoostBatchCSR batch);
265 
277 XGB_EXTERN_C typedef int XGBCallbackDataIterNext( // NOLINT(*)
278  DataIterHandle data_handle, XGBCallbackSetData *set_function,
279  DataHolderHandle set_function_handle);
280 
290  DataIterHandle data_handle,
291  XGBCallbackDataIterNext* callback,
292  const char* cache_info,
293  DMatrixHandle *out);
294 
295 /* == Second set of callback functions, used by constructing Quantile based DMatrix. ===
296  *
297  * Short note for how to use the second set of callback for GPU Hist tree method.
298  *
299  * Step 0: Define a data iterator with 2 methods `reset`, and `next`.
300  * Step 1: Create a DMatrix proxy by `XGProxyDMatrixCreate` and hold the handle.
301  * Step 2: Pass the iterator handle, proxy handle and 2 methods into
302  * `XGDeviceQuantileDMatrixCreateFromCallback`.
303  * Step 3: Call appropriate data setters in `next` functions.
304  *
305  * See test_iterative_device_dmatrix.cu or Python interface for examples.
306  */
307 
316 
324 XGB_EXTERN_C typedef int XGDMatrixCallbackNext(DataIterHandle iter); // NOLINT(*)
325 
329 XGB_EXTERN_C typedef void DataIterResetCallback(DataIterHandle handle); // NOLINT(*)
330 
347  XGDMatrixCallbackNext *next, float missing, int nthread, int max_bin,
348  DMatrixHandle *out);
359  DMatrixHandle handle,
360  const char* c_interface_str);
371  DMatrixHandle handle,
372  const char* c_interface_str);
373 /*
374  * ==========================- End data callback APIs ==========================
375  */
376 
377 
378 
388  const int *idxset,
389  bst_ulong len,
390  DMatrixHandle *out);
401  const int *idxset,
402  bst_ulong len,
403  DMatrixHandle *out,
404  int allow_groups);
418  const char *fname, int silent);
419 
428  char const* field,
429  char const* c_interface_str);
430 
440  const char *field,
441  const float *array,
442  bst_ulong len);
452  const char *field,
453  const unsigned *array,
454  bst_ulong len);
455 
481 XGB_DLL int XGDMatrixSetStrFeatureInfo(DMatrixHandle handle, const char *field,
482  const char **features,
483  const bst_ulong size);
484 
520 XGB_DLL int XGDMatrixGetStrFeatureInfo(DMatrixHandle handle, const char *field,
521  bst_ulong *size,
522  const char ***out_features);
523 
549 XGB_DLL int XGDMatrixSetDenseInfo(DMatrixHandle handle, const char *field,
550  void *data, bst_ulong size, int type);
551 
560  const unsigned *group,
561  bst_ulong len);
562 
572  const char *field,
573  bst_ulong* out_len,
574  const float **out_dptr);
584  const char *field,
585  bst_ulong* out_len,
586  const unsigned **out_dptr);
594  bst_ulong *out);
602  bst_ulong *out);
603 // --- start XGBoost class
611 XGB_DLL int XGBoosterCreate(const DMatrixHandle dmats[],
612  bst_ulong len,
613  BoosterHandle *out);
620 
634 XGB_DLL int XGBoosterSlice(BoosterHandle handle, int begin_layer,
635  int end_layer, int step,
636  BoosterHandle *out);
637 
645 XGB_DLL int XGBoosterBoostedRounds(BoosterHandle handle, int* out);
646 
655  const char *name,
656  const char *value);
657 
664  bst_ulong *out);
665 
674  int iter,
675  DMatrixHandle dtrain);
687  DMatrixHandle dtrain,
688  float *grad,
689  float *hess,
690  bst_ulong len);
702  int iter,
703  DMatrixHandle dmats[],
704  const char *evnames[],
705  bst_ulong len,
706  const char **out_result);
707 
732  DMatrixHandle dmat,
733  int option_mask,
734  unsigned ntree_limit,
735  int training,
736  bst_ulong *out_len,
737  const float **out_result);
794  DMatrixHandle dmat,
795  char const* c_json_config,
796  bst_ulong const **out_shape,
797  bst_ulong *out_dim,
798  float const **out_result);
799 /*
800  * \brief Inplace prediction from CPU dense matrix.
801  *
802  * \param handle Booster handle.
803  * \param values JSON encoded __array_interface__ to values.
804  * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
805  *
806  * Additional fields for inplace prediction are:
807  * "missing": float
808  *
809  * \param m An optional (NULL if not available) proxy DMatrix instance
810  * storing meta info.
811  *
812  * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
813  * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
814  * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
815  *
816  * \return 0 when success, -1 when failure happens
817  */
819  char const *values,
820  char const *c_json_config,
821  DMatrixHandle m,
822  bst_ulong const **out_shape,
823  bst_ulong *out_dim,
824  const float **out_result);
825 
826 /*
827  * \brief Inplace prediction from CPU CSR matrix.
828  *
829  * \param handle Booster handle.
830  * \param indptr JSON encoded __array_interface__ to row pointer in CSR.
831  * \param indices JSON encoded __array_interface__ to column indices in CSR.
832  * \param values JSON encoded __array_interface__ to values in CSR..
833  * \param ncol Number of features in data.
834  * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
835  * Additional fields for inplace prediction are:
836  * "missing": float
837  *
838  * \param m An optional (NULL if not available) proxy DMatrix instance
839  * storing meta info.
840  *
841  * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
842  * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
843  * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
844  *
845  * \return 0 when success, -1 when failure happens
846  */
847 XGB_DLL int XGBoosterPredictFromCSR(BoosterHandle handle, char const *indptr,
848  char const *indices, char const *values,
849  bst_ulong ncol,
850  char const *c_json_config, DMatrixHandle m,
851  bst_ulong const **out_shape,
852  bst_ulong *out_dim,
853  const float **out_result);
854 
855 /*
856  * \brief Inplace prediction from CUDA Dense matrix (cupy in Python).
857  *
858  * \param handle Booster handle
859  * \param values JSON encoded __cuda_array_interface__ to values.
860  * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
861  * Additional fields for inplace prediction are:
862  * "missing": float
863  *
864  * \param m An optional (NULL if not available) proxy DMatrix instance
865  * storing meta info.
866  * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
867  * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
868  * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
869  *
870  * \return 0 when success, -1 when failure happens
871  */
873  BoosterHandle handle, char const *values, char const *c_json_config,
874  DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim,
875  const float **out_result);
876 
877 /*
878  * \brief Inplace prediction from CUDA dense dataframe (cuDF in Python).
879  *
880  * \param handle Booster handle
881  * \param values List of __cuda_array_interface__ for all columns encoded in JSON list.
882  * \param c_json_config See `XGBoosterPredictFromDMatrix` for more info.
883  * Additional fields for inplace prediction are:
884  * "missing": float
885  *
886  * \param m An optional (NULL if not available) proxy DMatrix instance
887  * storing meta info.
888  * \param out_shape See `XGBoosterPredictFromDMatrix` for more info.
889  * \param out_dim See `XGBoosterPredictFromDMatrix` for more info.
890  * \param out_result See `XGBoosterPredictFromDMatrix` for more info.
891  *
892  * \return 0 when success, -1 when failure happens
893  */
895  BoosterHandle handle, char const *values, char const *c_json_config,
896  DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim,
897  const float **out_result);
898 
899 
900 /*
901  * ========================== Begin Serialization APIs =========================
902  */
903 /*
904  * Short note for serialization APIs. There are 3 different sets of serialization API.
905  *
906  * - Functions with the term "Model" handles saving/loading XGBoost model like trees or
907  * linear weights. Striping out parameters configuration like training algorithms or
908  * CUDA device ID. These functions are designed to let users reuse the trained model
909  * for different tasks, examples are prediction, training continuation or model
910  * interpretation.
911  *
912  * - Functions with the term "Config" handles save/loading configuration. It helps user
913  * to study the internal of XGBoost. Also user can use the load method for specifying
914  * paramters in a structured way. These functions are introduced in 1.0.0, and are not
915  * yet stable.
916  *
917  * - Functions with the term "Serialization" are combined of above two. They are used in
918  * situations like check-pointing, or continuing training task in distributed
919  * environment. In these cases the task must be carried out without any user
920  * intervention.
921  */
922 
930  const char *fname);
938  const char *fname);
947  const void *buf,
948  bst_ulong len);
958  const char **out_dptr);
959 
970  const char **out_dptr);
981  const void *buf, bst_ulong len);
982 
991  int* version);
992 
999 
1000 
1014  char const **out_str);
1025  char const *json_parameters);
1026 /*
1027  * =========================== End Serialization APIs ==========================
1028  */
1029 
1030 
1041  const char *fmap,
1042  int with_stats,
1043  bst_ulong *out_len,
1044  const char ***out_dump_array);
1045 
1057  const char *fmap,
1058  int with_stats,
1059  const char *format,
1060  bst_ulong *out_len,
1061  const char ***out_dump_array);
1062 
1075  int fnum,
1076  const char **fname,
1077  const char **ftype,
1078  int with_stats,
1079  bst_ulong *out_len,
1080  const char ***out_models);
1081 
1095  int fnum,
1096  const char **fname,
1097  const char **ftype,
1098  int with_stats,
1099  const char *format,
1100  bst_ulong *out_len,
1101  const char ***out_models);
1102 
1112  const char* key,
1113  const char** out,
1114  int *success);
1125  const char* key,
1126  const char* value);
1135  bst_ulong* out_len,
1136  const char*** out);
1137 
1153 XGB_DLL int XGBoosterSetStrFeatureInfo(BoosterHandle handle, const char *field,
1154  const char **features,
1155  const bst_ulong size);
1156 
1176 XGB_DLL int XGBoosterGetStrFeatureInfo(BoosterHandle handle, const char *field,
1177  bst_ulong *len,
1178  const char ***out_features);
1179 #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
XGDeviceQuantileDMatrixSetDataCudaArrayInterface
XGB_DLL int XGDeviceQuantileDMatrixSetDataCudaArrayInterface(DMatrixHandle handle, const char *c_interface_str)
Set data on a DMatrix proxy.
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...
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...
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:253
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.
XGDeviceQuantileDMatrixCreateFromCallback
XGB_DLL int XGDeviceQuantileDMatrixCreateFromCallback(DataIterHandle iter, DMatrixHandle proxy, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, float missing, int nthread, int max_bin, DMatrixHandle *out)
Create a device DMatrix with data iterator.
XGBoostBatchCSR
Mini batch used in XGBoost Data Iteration.
Definition: c_api.h:235
XGDMatrixSaveBinary
XGB_DLL int XGDMatrixSaveBinary(DMatrixHandle handle, const char *fname, int silent)
load a data matrix into binary file
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:237
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:255
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:229
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:249
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 reseting 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:231
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:239
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.
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.
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:246
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.
XGDMatrixSetDenseInfo
XGB_DLL int XGDMatrixSetDenseInfo(DMatrixHandle handle, const char *field, void *data, bst_ulong size, int type)
Set meta info from dense matrix. Valid field names are:
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.
XGDeviceQuantileDMatrixSetDataCudaColumnar
XGB_DLL int XGDeviceQuantileDMatrixSetDataCudaColumnar(DMatrixHandle handle, const char *c_interface_str)
Set data on a DMatrix proxy.
XGBoostBatchCSR::weight
float * weight
weight of each instance, can be NULL
Definition: c_api.h:251
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.
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