NAME
AI::XGBoost::CAPI::RAW - Perl wrapper for XGBoost C API https://github.com/dmlc/xgboost
VERSION
version 0.11
SYNOPSIS
use 5.010;
use AI::XGBoost::CAPI::RAW;
use FFI::Platypus;
my $silent = 0;
my ($dtrain, $dtest) = (0, 0);
AI::XGBoost::CAPI::RAW::XGDMatrixCreateFromFile('agaricus.txt.test', $silent, \$dtest);
AI::XGBoost::CAPI::RAW::XGDMatrixCreateFromFile('agaricus.txt.train', $silent, \$dtrain);
my ($rows, $cols) = (0, 0);
AI::XGBoost::CAPI::RAW::XGDMatrixNumRow($dtrain, \$rows);
AI::XGBoost::CAPI::RAW::XGDMatrixNumCol($dtrain, \$cols);
say "Dimensions: $rows, $cols";
my $booster = 0;
AI::XGBoost::CAPI::RAW::XGBoosterCreate( [$dtrain] , 1, \$booster);
for my $iter (0 .. 10) {
    AI::XGBoost::CAPI::RAW::XGBoosterUpdateOneIter($booster, $iter, $dtrain);
}
my $out_len = 0;
my $out_result = 0;
AI::XGBoost::CAPI::RAW::XGBoosterPredict($booster, $dtest, 0, 0, \$out_len, \$out_result);
my $ffi = FFI::Platypus->new();
my $predictions = $ffi->cast(opaque => "float[$out_len]", $out_result);
#say join "\n", @$predictions;
AI::XGBoost::CAPI::RAW::XGBoosterFree($booster);
AI::XGBoost::CAPI::RAW::XGDMatrixFree($dtrain);
AI::XGBoost::CAPI::RAW::XGDMatrixFree($dtest);
DESCRIPTION
Wrapper for the C API.
The doc for the methods is extracted from doxygen comments: https://github.com/dmlc/xgboost/blob/master/include/xgboost/c_api.h
FUNCTIONS
XGBGetLastError
Get string message of the last error
All functions in this file will return 0 when success and -1 when an error occurred, XGBGetLastError can be called to retrieve the error
This function is thread safe and can be called by different thread
Returns string error information
XGDMatrixCreateFromFile
Load a data matrix
Parameters:
- filename
 - 
the name of the file
 - silent
 - 
whether print messages during loading
 - out
 - 
a loaded data matrix
 
XGDMatrixCreateFromCSREx
Create a matrix content from CSR fromat
Parameters:
- indptr
 - 
pointer to row headers
 - indices
 - 
findex
 - data
 - 
fvalue
 - nindptr
 - 
number of rows in the matrix + 1
 - nelem
 - 
number of nonzero elements in the matrix
 - num_col
 - 
number of columns; when it's set to 0, then guess from data
 - out
 - 
created dmatrix
 
XGDMatrixCreateFromCSCEx
Create a matrix content from CSC format
Parameters:
- col_ptr
 - 
pointer to col headers
 - indices
 - 
findex
 - data
 - 
fvalue
 - nindptr
 - 
number of rows in the matrix + 1
 - nelem
 - 
number of nonzero elements in the matrix
 - num_row
 - 
number of rows; when it's set to 0, then guess from data
 
XGDMatrixCreateFromMat
Create matrix content from dense matrix
Parameters:
- data
 - 
pointer to the data space
 - nrow
 - 
number of rows
 - ncol
 - 
number columns
 - missing
 - 
which value to represent missing value
 - out
 - 
created dmatrix
 
XGDMatrixCreateFromMat_omp
Create matrix content from dense matrix
Parameters:
- data
 - 
pointer to the data space
 - nrow
 - 
number of rows
 - ncol
 - 
number columns
 - missing
 - 
which value to represent missing value
 - out
 - 
created dmatrix
 - nthread
 - 
number of threads (up to maximum cores available, if <=0 use all cores)
 
XGDMatrixSliceDMatrix
Create a new dmatrix from sliced content of existing matrix
Parameters:
- handle
 - 
instance of data matrix to be sliced
 - idxset
 - 
index set
 - len
 - 
length of index set
 - out
 - 
a sliced new matrix
 
XGDMatrixNumRow
Get number of rows.
Parameters:
- handle
 - 
the handle to the DMatrix
 - out
 - 
The address to hold number of rows.
 
XGDMatrixNumCol
Get number of cols.
Parameters:
- handle
 - 
the handle to the DMatrix
 - out
 - 
The address to hold number of cols.
 
XGDMatrixSaveBinary
load a data matrix into binary file
Parameters:
- handle
 - 
a instance of data matrix
 - fname
 - 
file name
 - silent
 - 
print statistics when saving
 
XGDMatrixSetFloatInfo
Set float vector to a content in info
Parameters:
- handle
 - 
a instance of data matrix
 - field
 - 
field name, can be label, weight
 - array
 - 
pointer to float vector
 - len
 - 
length of array
 
XGDMatrixSetUIntInfo
Set uint32 vector to a content in info
Parameters:
- handle
 - 
a instance of data matrix
 - field
 - 
field name, can be label, weight
 - array
 - 
pointer to unsigned int vector
 - len
 - 
length of array
 
XGDMatrixSetGroup
Set label of the training matrix
Parameters:
- handle
 - 
a instance of data matrix
 - group
 - 
pointer to group size
 - len
 - 
length of the array
 
XGDMatrixGetFloatInfo
Get float info vector from matrix
Parameters:
- handle
 - 
a instance of data matrix
 - field
 - 
field name
 - out_len
 - 
used to set result length
 - out_dptr
 - 
pointer to the result
 
XGDMatrixGetUIntInfo
Get uint32 info vector from matrix
Parameters:
- handle
 - 
a instance of data matrix
 - field
 - 
field name
 - out_len
 - 
The length of the field
 - out_dptr
 - 
pointer to the result
 
XGDMatrixFree
Free space in data matrix
XGBoosterCreate
Create xgboost learner
Parameters:
- dmats
 - 
matrices that are set to be cached
 - len
 - 
length of dmats
 - out
 - 
handle to the result booster
 
XGBoosterFree
Free obj in handle
Parameters:
- handle
 - 
handle to be freed
 
XGBoosterSetParam
Update the model in one round using dtrain
Parameters:
- handle
 - 
handle
 - name
 - 
parameter name
 - value
 - 
value of parameter
 
XGBoosterBoostOneIter
Update the modelo, by directly specify grandient and second order gradient, this can be used to replace UpdateOneIter, to support customized loss function
Parameters:
- handle
 - 
handle
 - dtrain
 - 
training data
 - grad
 - 
gradient statistics
 - hess
 - 
second order gradinet statistics
 - len
 - 
length of grad/hess array
 
XGBoosterUpdateOneIter
Update the model in one round using dtrain
Parameters:
- handle
 - 
handle
 - iter
 - 
current iteration rounds
 - dtrain
 - 
training data
 
XGBoosterEvalOneIter
XGBoosterPredict
Make prediction based on dmat
Parameters:
- handle
 - 
handle
 - dmat
 - 
data matrix
 - option_mask
 - 
bit-mask of options taken in prediction, possible values
0: normal prediction
1: output margin instead of transformed value
2: output leaf index of trees instead of leaf value, note leaf index is unique per tree
4: output feature contributions to individual predictions
 - ntree_limit
 - 
limit number of trees used for prediction, this is only valid for boosted trees when the parameter is set to 0, we will use all the trees
 - out_len
 - 
used to store length of returning result
 - out_result
 - 
used to set a pointer to array
 
XGBoosterLoadModel
Load model form existing file
Parameters:
- handle
 - 
handle
 - fname
 - 
file name
 
XGBoosterSaveModel
Save model into existing file
Parameters:
- handle
 - 
handle
 - fname
 - 
file name
 
XGBoosterLoadModelFromBuffer
XGBoosterGetModelRaw
XGBoosterDumpModel
XGBoosterDumpModelEx
XGBoosterDumpModelWithFeatures
XGBoosterDumpModelExWithFeatures
XGBoosterSetAttr
XGBoosterGetAttr
XGBoosterGetAttrNames
XGBoosterLoadRabitCheckpoint
XGBoosterSaveRabitCheckpoint
AUTHOR
Pablo Rodríguez González <pablo.rodriguez.gonzalez@gmail.com>
COPYRIGHT AND LICENSE
Copyright (c) 2017 by Pablo Rodríguez González.