NAME
AI::XGBoost::CAPI - Perl wrapper for XGBoost C API https://github.com/dmlc/xgboost
VERSION
version 0.002
SYNOPSIS
use 5.010;
use AI::XGBoost::CAPI;
use FFI::Platypus;
my $silent = 0;
my ($dtrain, $dtest) = (0, 0);
AI::XGBoost::CAPI::XGDMatrixCreateFromFile('agaricus.txt.test', $silent, \$dtest);
AI::XGBoost::CAPI::XGDMatrixCreateFromFile('agaricus.txt.train', $silent, \$dtrain);
my ($rows, $cols) = (0, 0);
AI::XGBoost::CAPI::XGDMatrixNumRow($dtrain, \$rows);
AI::XGBoost::CAPI::XGDMatrixNumCol($dtrain, \$cols);
say "Dimensions: $rows, $cols";
my $booster = 0;
AI::XGBoost::CAPI::XGBoosterCreate( [$dtrain] , 1, \$booster);
for my $iter (0 .. 10) {
AI::XGBoost::CAPI::XGBoosterUpdateOneIter($booster, $iter, $dtrain);
}
my $out_len = 0;
my $out_result = 0;
AI::XGBoost::CAPI::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::XGBoosterFree($booster);
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
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
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
XGBoosterUpdateOneIter
Update the model in one round using dtrain
Parameters:
- handle
-
handle
- iter
-
current iteration rounds
- dtrain
-
training data
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
AUTHOR
Pablo Rodríguez González <pablo.rodriguez.gonzalez@gmail.com>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2017 by Pablo Rodríguez González.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004