C API — LightGBM 4.6.0.99 documentation (original) (raw)

Copyright

Copyright (c) 2016 Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE file in the project root for license information.

Note

To avoid type conversion on large data, the most of our exposed interface supports both float32 and float64, except the following:

  1. gradient and Hessian;
  2. current score for training and validation data.

The reason is that they are called frequently, and the type conversion on them may be time-cost.

Defines

C_API_DTYPE_FLOAT32 (0)

float32 (single precision float).

C_API_DTYPE_FLOAT64 (1)

float64 (double precision float).

C_API_DTYPE_INT32 (2)

int32.

C_API_DTYPE_INT64 (3)

int64.

C_API_FEATURE_IMPORTANCE_GAIN (1)

Gain type of feature importance.

C_API_FEATURE_IMPORTANCE_SPLIT (0)

Split type of feature importance.

C_API_MATRIX_TYPE_CSC (1)

CSC sparse matrix type.

C_API_MATRIX_TYPE_CSR (0)

CSR sparse matrix type.

C_API_PREDICT_CONTRIB (3)

Predict feature contributions (SHAP values).

C_API_PREDICT_LEAF_INDEX (2)

Predict leaf index.

C_API_PREDICT_NORMAL (0)

Normal prediction, with transform (if needed).

C_API_PREDICT_RAW_SCORE (1)

Predict raw score.

INLINE_FUNCTION inline

Inline specifier.

THREAD_LOCAL thread_local

Thread local specifier.

Typedefs

typedef void *BoosterHandle

Handle of booster.

typedef void *ByteBufferHandle

Handle of ByteBuffer.

typedef void *DatasetHandle

Handle of dataset.

typedef void *FastConfigHandle

Handle of FastConfig.

Functions

static char *LastErrorMsg()

Handle of error message.

Returns:

Error message

LIGHTGBM_C_EXPORT int LGBM_BoosterAddValidData(BoosterHandle handle, const DatasetHandle valid_data)

Add new validation data to booster.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterCalcNumPredict(BoosterHandle handle, int num_row, int predict_type, int start_iteration, int num_iteration, int64_t *out_len)

Get number of predictions.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterCreate(const DatasetHandle train_data, const char *parameters, BoosterHandle *out)

Create a new boosting learner.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterCreateFromModelfile(const char *filename, int *out_num_iterations, BoosterHandle *out)

Load an existing booster from model file.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterDumpModel(BoosterHandle handle, int start_iteration, int num_iteration, int feature_importance_type, int64_t buffer_len, int64_t *out_len, char *out_str)

Dump model to JSON.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterFeatureImportance(BoosterHandle handle, int num_iteration, int importance_type, double *out_results)

Get model feature importance.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterFree(BoosterHandle handle)

Free space for booster.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterFreePredictSparse(void *indptr, int32_t *indices, void *data, int indptr_type, int data_type)

Method corresponding to LGBM_BoosterPredictSparseOutput to free the allocated data.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetCurrentIteration(BoosterHandle handle, int *out_iteration)

Get index of the current boosting iteration.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetEval(BoosterHandle handle, int data_idx, int *out_len, double *out_results)

Get evaluation for training data and validation data.

Note

  1. You should call LGBM_BoosterGetEvalNames first to get the names of evaluation metrics.
  2. You should pre-allocate memory for out_results, you can get its length by LGBM_BoosterGetEvalCounts.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetEvalCounts(BoosterHandle handle, int *out_len)

Get number of evaluation metrics.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetEvalNames(BoosterHandle handle, const int len, int *out_len, const size_t buffer_len, size_t *out_buffer_len, char **out_strs)

Get names of evaluation metrics.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetFeatureNames(BoosterHandle handle, const int len, int *out_len, const size_t buffer_len, size_t *out_buffer_len, char **out_strs)

Get names of features.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetLeafValue(BoosterHandle handle, int tree_idx, int leaf_idx, double *out_val)

Get leaf value.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetLinear(BoosterHandle handle, int *out)

Get int representing whether booster is fitting linear trees.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetLoadedParam(BoosterHandle handle, int64_t buffer_len, int64_t *out_len, char *out_str)

Get parameters as JSON string.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetLowerBoundValue(BoosterHandle handle, double *out_results)

Get model lower bound value.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetNumClasses(BoosterHandle handle, int *out_len)

Get number of classes.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetNumFeature(BoosterHandle handle, int *out_len)

Get number of features.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetNumPredict(BoosterHandle handle, int data_idx, int64_t *out_len)

Get number of predictions for training data and validation data (this can be used to support customized evaluation functions).

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetPredict(BoosterHandle handle, int data_idx, int64_t *out_len, double *out_result)

Get prediction for training data and validation data.

Note

You should pre-allocate memory for out_result, its length is equal to num_class * num_data.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterGetUpperBoundValue(BoosterHandle handle, double *out_results)

Get model upper bound value.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterLoadModelFromString(const char *model_str, int *out_num_iterations, BoosterHandle *out)

Load an existing booster from string.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterMerge(BoosterHandle handle, BoosterHandle other_handle)

Merge model from other_handle into handle.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterNumberOfTotalModel(BoosterHandle handle, int *out_models)

Get number of weak sub-models.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterNumModelPerIteration(BoosterHandle handle, int *out_tree_per_iteration)

Get number of trees per iteration.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForArrow(BoosterHandle handle, int64_t n_chunks, const ArrowArray *chunks, const ArrowSchema *schema, int predict_type, int start_iteration, int num_iteration, const char *parameter, int64_t *out_len, double *out_result)

Make prediction for a new dataset.

Note

You should pre-allocate memory for out_result:

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForCSC(BoosterHandle handle, const void *col_ptr, int col_ptr_type, const int32_t *indices, const void *data, int data_type, int64_t ncol_ptr, int64_t nelem, int64_t num_row, int predict_type, int start_iteration, int num_iteration, const char *parameter, int64_t *out_len, double *out_result)

Make prediction for a new dataset in CSC format.

Note

You should pre-allocate memory for out_result:

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForCSR(BoosterHandle handle, const void *indptr, int indptr_type, const int32_t *indices, const void *data, int data_type, int64_t nindptr, int64_t nelem, int64_t num_col, int predict_type, int start_iteration, int num_iteration, const char *parameter, int64_t *out_len, double *out_result)

Make prediction for a new dataset in CSR format.

Note

You should pre-allocate memory for out_result:

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForCSRSingleRow(BoosterHandle handle, const void *indptr, int indptr_type, const int32_t *indices, const void *data, int data_type, int64_t nindptr, int64_t nelem, int64_t num_col, int predict_type, int start_iteration, int num_iteration, const char *parameter, int64_t *out_len, double *out_result)

Make prediction for a new dataset in CSR format. This method re-uses the internal predictor structure from previous calls and is optimized for single row invocation.

Note

You should pre-allocate memory for out_result:

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForCSRSingleRowFast(FastConfigHandle fastConfig_handle, const void *indptr, const int indptr_type, const int32_t *indices, const void *data, const int64_t nindptr, const int64_t nelem, int64_t *out_len, double *out_result)

Faster variant of LGBM_BoosterPredictForCSRSingleRow.

Score single rows after setup with LGBM_BoosterPredictForCSRSingleRowFastInit.

By removing the setup steps from this call extra optimizations can be made like initializing the config only once, instead of once per call.

Note

Setting up the number of threads is only done once at LGBM_BoosterPredictForCSRSingleRowFastInit instead of at each prediction. If you use a different number of threads in other calls, you need to start the setup process over, or that number of threads will be used for these calls as well.

Note

You should pre-allocate memory for out_result:

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForCSRSingleRowFastInit(BoosterHandle handle, const int predict_type, const int start_iteration, const int num_iteration, const int data_type, const int64_t num_col, const char *parameter, FastConfigHandle *out_fastConfig)

Initialize and return a FastConfigHandle for use with LGBM_BoosterPredictForCSRSingleRowFast.

Release the FastConfig by passing its handle to LGBM_FastConfigFree when no longer needed.

Parameters:

Returns:

0 when it succeeds, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForFile(BoosterHandle handle, const char *data_filename, int data_has_header, int predict_type, int start_iteration, int num_iteration, const char *parameter, const char *result_filename)

Make prediction for file.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForMat(BoosterHandle handle, const void *data, int data_type, int32_t nrow, int32_t ncol, int is_row_major, int predict_type, int start_iteration, int num_iteration, const char *parameter, int64_t *out_len, double *out_result)

Make prediction for a new dataset.

Note

You should pre-allocate memory for out_result:

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForMats(BoosterHandle handle, const void **data, int data_type, int32_t nrow, int32_t ncol, int predict_type, int start_iteration, int num_iteration, const char *parameter, int64_t *out_len, double *out_result)

Make prediction for a new dataset presented in a form of array of pointers to rows.

Note

You should pre-allocate memory for out_result:

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForMatSingleRow(BoosterHandle handle, const void *data, int data_type, int ncol, int is_row_major, int predict_type, int start_iteration, int num_iteration, const char *parameter, int64_t *out_len, double *out_result)

Make prediction for a new dataset. This method re-uses the internal predictor structure from previous calls and is optimized for single row invocation.

Note

You should pre-allocate memory for out_result:

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForMatSingleRowFast(FastConfigHandle fastConfig_handle, const void *data, int64_t *out_len, double *out_result)

Faster variant of LGBM_BoosterPredictForMatSingleRow.

Score a single row after setup with LGBM_BoosterPredictForMatSingleRowFastInit.

By removing the setup steps from this call extra optimizations can be made like initializing the config only once, instead of once per call.

Note

Setting up the number of threads is only done once at LGBM_BoosterPredictForMatSingleRowFastInit instead of at each prediction. If you use a different number of threads in other calls, you need to start the setup process over, or that number of threads will be used for these calls as well.

Parameters:

Returns:

0 when it succeeds, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForMatSingleRowFastInit(BoosterHandle handle, const int predict_type, const int start_iteration, const int num_iteration, const int data_type, const int32_t ncol, const char *parameter, FastConfigHandle *out_fastConfig)

Initialize and return a FastConfigHandle for use with LGBM_BoosterPredictForMatSingleRowFast.

Release the FastConfig by passing its handle to LGBM_FastConfigFree when no longer needed.

Parameters:

Returns:

0 when it succeeds, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterPredictSparseOutput(BoosterHandle handle, const void *indptr, int indptr_type, const int32_t *indices, const void *data, int data_type, int64_t nindptr, int64_t nelem, int64_t num_col_or_row, int predict_type, int start_iteration, int num_iteration, const char *parameter, int matrix_type, int64_t *out_len, void **out_indptr, int32_t **out_indices, void **out_data)

Make sparse prediction for a new dataset in CSR or CSC format. Currently only used for feature contributions.

Note

The outputs are pre-allocated, as they can vary for each invocation, but the shape should be the same:

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterRefit(BoosterHandle handle, const int32_t *leaf_preds, int32_t nrow, int32_t ncol)

Refit the tree model using the new data (online learning).

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterResetParameter(BoosterHandle handle, const char *parameters)

Reset config for booster.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterResetTrainingData(BoosterHandle handle, const DatasetHandle train_data)

Reset training data for booster.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterRollbackOneIter(BoosterHandle handle)

Rollback one iteration.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterSaveModel(BoosterHandle handle, int start_iteration, int num_iteration, int feature_importance_type, const char *filename)

Save model into file.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterSaveModelToString(BoosterHandle handle, int start_iteration, int num_iteration, int feature_importance_type, int64_t buffer_len, int64_t *out_len, char *out_str)

Save model to string.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterSetLeafValue(BoosterHandle handle, int tree_idx, int leaf_idx, double val)

Set leaf value.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterShuffleModels(BoosterHandle handle, int start_iter, int end_iter)

Shuffle models.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterUpdateOneIter(BoosterHandle handle, int *is_finished)

Update the model for one iteration.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterUpdateOneIterCustom(BoosterHandle handle, const float *grad, const float *hess, int *is_finished)

Update the model by specifying gradient and Hessian directly (this can be used to support customized loss functions).

Note

The length of the arrays referenced by grad and hess must be equal to num_class * num_train_data, this is not verified by the library, the caller must ensure this.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_BoosterValidateFeatureNames(BoosterHandle handle, const char **data_names, int data_num_features)

Check that the feature names of the data match the ones used to train the booster.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_ByteBufferFree(ByteBufferHandle handle)

Free space for byte buffer.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_ByteBufferGetAt(ByteBufferHandle handle, int32_t index, uint8_t *out_val)

Get a ByteBuffer value at an index.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetAddFeaturesFrom(DatasetHandle target, DatasetHandle source)

Add features from source to target.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetCreateByReference(const DatasetHandle reference, int64_t num_total_row, DatasetHandle *out)

Allocate the space for dataset and bucket feature bins according to reference dataset.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromArrow(int64_t n_chunks, const ArrowArray *chunks, const ArrowSchema *schema, const char *parameters, const DatasetHandle reference, DatasetHandle *out)

Create dataset from Arrow.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromCSC(const void *col_ptr, int col_ptr_type, const int32_t *indices, const void *data, int data_type, int64_t ncol_ptr, int64_t nelem, int64_t num_row, const char *parameters, const DatasetHandle reference, DatasetHandle *out)

Create a dataset from CSC format.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromCSR(const void *indptr, int indptr_type, const int32_t *indices, const void *data, int data_type, int64_t nindptr, int64_t nelem, int64_t num_col, const char *parameters, const DatasetHandle reference, DatasetHandle *out)

Create a dataset from CSR format.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromCSRFunc(void *get_row_funptr, int num_rows, int64_t num_col, const char *parameters, const DatasetHandle reference, DatasetHandle *out)

Create a dataset from CSR format through callbacks.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromFile(const char *filename, const char *parameters, const DatasetHandle reference, DatasetHandle *out)

Load dataset from file (like LightGBM CLI version does).

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromMat(const void *data, int data_type, int32_t nrow, int32_t ncol, int is_row_major, const char *parameters, const DatasetHandle reference, DatasetHandle *out)

Create dataset from dense matrix.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromMats(int32_t nmat, const void **data, int data_type, int32_t *nrow, int32_t ncol, int *is_row_major, const char *parameters, const DatasetHandle reference, DatasetHandle *out)

Create dataset from array of dense matrices.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromSampledColumn(double **sample_data, int **sample_indices, int32_t ncol, const int *num_per_col, int32_t num_sample_row, int32_t num_local_row, int64_t num_dist_row, const char *parameters, DatasetHandle *out)

Allocate the space for dataset and bucket feature bins according to sampled data.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromSerializedReference(const void *ref_buffer, int32_t ref_buffer_size, int64_t num_row, int32_t num_classes, const char *parameters, DatasetHandle *out)

Allocate the space for dataset and bucket feature bins according to serialized reference dataset.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetDumpText(DatasetHandle handle, const char *filename)

Save dataset to text file, intended for debugging use only.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetFree(DatasetHandle handle)

Free space for dataset.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetGetFeatureNames(DatasetHandle handle, const int len, int *num_feature_names, const size_t buffer_len, size_t *out_buffer_len, char **feature_names)

Get feature names of dataset.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetGetFeatureNumBin(DatasetHandle handle, int feature, int *out)

Get number of bins for feature.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetGetField(DatasetHandle handle, const char *field_name, int *out_len, const void **out_ptr, int *out_type)

Get info vector from dataset.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetGetNumData(DatasetHandle handle, int *out)

Get number of data points.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetGetNumFeature(DatasetHandle handle, int *out)

Get number of features.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetGetSubset(const DatasetHandle handle, const int32_t *used_row_indices, int32_t num_used_row_indices, const char *parameters, DatasetHandle *out)

Create subset of a data.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetInitStreaming(DatasetHandle dataset, int32_t has_weights, int32_t has_init_scores, int32_t has_queries, int32_t nclasses, int32_t nthreads, int32_t omp_max_threads)

Initialize the Dataset for streaming.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetMarkFinished(DatasetHandle dataset)

Mark the Dataset as complete by calling dataset->FinishLoad.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetPushRows(DatasetHandle dataset, const void *data, int data_type, int32_t nrow, int32_t ncol, int32_t start_row)

Push data to existing dataset, if nrow + start_row == num_total_row, will call dataset->FinishLoad.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetPushRowsByCSR(DatasetHandle dataset, const void *indptr, int indptr_type, const int32_t *indices, const void *data, int data_type, int64_t nindptr, int64_t nelem, int64_t num_col, int64_t start_row)

Push data to existing dataset, if nrow + start_row == num_total_row, will call dataset->FinishLoad.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetPushRowsByCSRWithMetadata(DatasetHandle dataset, const void *indptr, int indptr_type, const int32_t *indices, const void *data, int data_type, int64_t nindptr, int64_t nelem, int64_t start_row, const float *label, const float *weight, const double *init_score, const int32_t *query, int32_t tid)

Push CSR data to existing dataset. (See LGBM_DatasetPushRowsWithMetadata for more details.)

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetPushRowsWithMetadata(DatasetHandle dataset, const void *data, int data_type, int32_t nrow, int32_t ncol, int32_t start_row, const float *label, const float *weight, const double *init_score, const int32_t *query, int32_t tid)

Push data to existing dataset. The general flow for a streaming scenario is:

  1. create Dataset “schema” (e.g. LGBM_DatasetCreateFromSampledColumn)
  2. init them for thread-safe streaming (LGBM_DatasetInitStreaming)
  3. push data (LGBM_DatasetPushRowsWithMetadata or LGBM_DatasetPushRowsByCSRWithMetadata)
  4. call LGBM_DatasetMarkFinished

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetSaveBinary(DatasetHandle handle, const char *filename)

Save dataset to binary file.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetSerializeReferenceToBinary(DatasetHandle handle, ByteBufferHandle *out, int32_t *out_len)

Create a dataset schema representation as a binary byte array (excluding data).

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetSetFeatureNames(DatasetHandle handle, const char **feature_names, int num_feature_names)

Save feature names to dataset.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetSetField(DatasetHandle handle, const char *field_name, const void *field_data, int num_element, int type)

Set vector to a content in info.

Note

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetSetFieldFromArrow(DatasetHandle handle, const char *field_name, int64_t n_chunks, const ArrowArray *chunks, const ArrowSchema *schema)

Set vector to a content in info.

Note

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetSetWaitForManualFinish(DatasetHandle dataset, int wait)

Set whether or not the Dataset waits for a manual MarkFinished call or calls FinishLoad on itself automatically. Set to 1 for streaming scenario, and use LGBM_DatasetMarkFinished to manually finish the Dataset.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DatasetUpdateParamChecking(const char *old_parameters, const char *new_parameters)

Raise errors for attempts to update dataset parameters.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_DumpParamAliases(int64_t buffer_len, int64_t *out_len, char *out_str)

Dump all parameter names with their aliases to JSON.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_FastConfigFree(FastConfigHandle fastConfig)

Release FastConfig object.

Parameters:

Returns:

0 when it succeeds, -1 when failure happens

LIGHTGBM_C_EXPORT const char *LGBM_GetLastError()

Get string message of the last error.

Returns:

Error information

LIGHTGBM_C_EXPORT int LGBM_GetMaxThreads(int *out)

Get current maximum number of threads used by LightGBM routines in this process.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_GetSampleCount(int32_t num_total_row, const char *parameters, int *out)

Get number of samples based on parameters and total number of rows of data.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_NetworkFree()

Finalize the network.

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_NetworkInit(const char *machines, int local_listen_port, int listen_time_out, int num_machines)

Initialize the network.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_NetworkInitWithFunctions(int num_machines, int rank, void *reduce_scatter_ext_fun, void *allgather_ext_fun)

Initialize the network with external collective functions.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_RegisterLogCallback(void (*callback)(const char*))

Register a callback function for log redirecting.

Parameters:

Returns:

0 when succeed, -1 when failure happens

LIGHTGBM_C_EXPORT int LGBM_SampleIndices(int32_t num_total_row, const char *parameters, void *out, int32_t *out_len)

Create sample indices for total number of rows.

Note

You should pre-allocate memory for out, you can get its length by LGBM_GetSampleCount.

Parameters:

Returns:

0 when succeed, -1 when failure happens

inline void LGBM_SetLastError(const char *msg)

Set string message of the last error.

Note

This will call unsafe sprintf when compiled using C standards before C99.

Parameters:

LIGHTGBM_C_EXPORT int LGBM_SetMaxThreads(int num_threads)

Set maximum number of threads used by LightGBM routines in this process.

Parameters:

Returns:

0 when succeed, -1 when failure happens