AI::XGBoost::CAPI::RAW - Perl wrapper for XGBoost C API https://github.com/dmlc/xgboost
version 0.004
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);
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
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
Load a data matrix
Parameters:
the name of the file
whether print messages during loading
a loaded data matrix
Create a matrix content from CSR fromat
pointer to row headers
findex
fvalue
number of rows in the matrix + 1
number of nonzero elements in the matrix
number of columns; when it's set to 0, then guess from data
created dmatrix
Create a matrix content from CSC format
pointer to col headers
number of rows; when it's set to 0, then guess from data
Create matrix content from dense matrix
pointer to the data space
number of rows
number columns
which value to represent missing value
Create a new dmatrix from sliced content of existing matrix
instance of data matrix to be sliced
index set
length of index set
a sliced new matrix
Get number of rows.
the handle to the DMatrix
The address to hold number of rows.
Get number of cols.
The address to hold number of cols.
load a data matrix into binary file
a instance of data matrix
file name
print statistics when saving
Set float vector to a content in info
field name, can be label, weight
pointer to float vector
length of array
Set uint32 vector to a content in info
pointer to unsigned int vector
Set label of the training matrix
pointer to group size
length of the array
Get float info vector from matrix
field name
used to set result length
pointer to the result
Get uint32 info vector from matrix
The length of the field
Free space in data matrix
Create xgboost learner
matrices that are set to be cached
length of dmats
handle to the result booster
Free obj in handle
handle to be freed
Update the model in one round using dtrain
handle
parameter name
value of parameter
Update the modelo, by directly specify grandient and second order gradient, this can be used to replace UpdateOneIter, to support customized loss function
training data
gradient statistics
second order gradinet statistics
length of grad/hess array
current iteration rounds
Make prediction based on dmat
data matrix
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
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
used to store length of returning result
used to set a pointer to array
Load model form existing file
Save model into existing file
Pablo Rodríguez González <pablo.rodriguez.gonzalez@gmail.com>
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
To install AI::XGBoost, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AI::XGBoost
CPAN shell
perl -MCPAN -e shell install AI::XGBoost
For more information on module installation, please visit the detailed CPAN module installation guide.