LGBM_BoosterPredictSparseOutput

Function LGBM_BoosterPredictSparseOutput 

Source
pub unsafe extern "C" fn LGBM_BoosterPredictSparseOutput(
    handle: BoosterHandle,
    indptr: *const c_void,
    indptr_type: c_int,
    indices: *const i32,
    data: *const c_void,
    data_type: c_int,
    nindptr: i64,
    nelem: i64,
    num_col_or_row: i64,
    predict_type: c_int,
    start_iteration: c_int,
    num_iteration: c_int,
    parameter: *const c_char,
    matrix_type: c_int,
    out_len: *mut i64,
    out_indptr: *mut *mut c_void,
    out_indices: *mut *mut i32,
    out_data: *mut *mut c_void,
) -> c_int
Expand description

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:

  • for feature contributions, the shape of sparse matrix will be num_class * num_data * (num_feature + 1). The output indptr_type for the sparse matrix will be the same as the given input indptr_type. Call LGBM_BoosterFreePredictSparse to deallocate resources.

§Arguments

  • handle - Handle of booster
  • indptr - Pointer to row headers for CSR or column headers for CSC
  • indptr_type - Type of indptr, can be C_API_DTYPE_INT32 or C_API_DTYPE_INT64
  • indices - Pointer to column indices for CSR or row indices for CSC
  • data - Pointer to the data space
  • data_type - Type of data pointer, can be C_API_DTYPE_FLOAT32 or C_API_DTYPE_FLOAT64
  • nindptr - Number of entries in indptr
  • nelem - Number of nonzero elements in the matrix
  • num_col_or_row - Number of columns for CSR or number of rows for CSC
  • predict_type - What should be predicted, only feature contributions supported currently
  • C_API_PREDICT_CONTRIB: feature contributions (SHAP values)
  • start_iteration - Start index of the iteration to predict
  • num_iteration - Number of iterations for prediction, <= 0 means no limit
  • parameter - Other parameters for prediction, e.g. early stopping for prediction
  • matrix_type - Type of matrix input and output, can be C_API_MATRIX_TYPE_CSR or C_API_MATRIX_TYPE_CSC
  • out_len (direction out) - Length of output data and output indptr (pointer to an array with two entries where to write them)
  • out_indptr (direction out) - Pointer to output row headers for CSR or column headers for CSC
  • out_indices (direction out) - Pointer to sparse column indices for CSR or row indices for CSC
  • out_data (direction out) - Pointer to sparse data space

§Returns

0 when succeed, -1 when failure happens