AI::XGBoost::CAPI - Perl wrapper for XGBoost C API https://github.com/dmlc/xgboost
version 0.11
use 5.010; use AI::XGBoost::CAPI qw(:all); my $dtrain = XGDMatrixCreateFromFile('agaricus.txt.train'); my $dtest = XGDMatrixCreateFromFile('agaricus.txt.test'); my ($rows, $cols) = (XGDMatrixNumRow($dtrain), XGDMatrixNumCol($dtrain)); say "Train dimensions: $rows, $cols"; my $booster = XGBoosterCreate([$dtrain]); for my $iter (0 .. 10) { XGBoosterUpdateOneIter($booster, $iter, $dtrain); } my $predictions = XGBoosterPredict($booster, $dtest); # say join "\n", @$predictions; XGBoosterFree($booster); XGDMatrixFree($dtrain); XGDMatrixFree($dtest);
Perlified wrapper for the C API
XGBoost c api functions returns some int to signal the presence/absence of error. In this module that is achieved using Exceptions from Exception::Class
Load a data matrix
Parameters:
the name of the file
whether print messages during loading
Returns a loaded data matrix
Create from dense matrix
matrix data
value indicating missing data (optional)
Get number of rows
DMatrix
Get number of cols
Free space in data matrix
DMatrix to be freed
Create XGBoost learner
matrices that are set to be cached
Update the model in one round using train matrix
XGBoost learner to train
current iteration rounds
training data
Make prediction based on train matrix
XGBoost learner
Data matrix with the elements to predict
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
Returns an arrayref with the predictions corresponding to the rows of data matrix
Free booster object
booster to be freed
Pablo Rodríguez González <pablo.rodriguez.gonzalez@gmail.com>
Copyright (c) 2017 by Pablo Rodríguez González.
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.