AI::XGBoost::CAPI - Perl wrapper for XGBoost C API https://github.com/dmlc/xgboost
version 0.001
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);
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
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.
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
current iteration rounds
training data
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
Pablo Rodríguez González <pablo.rodriguez.gonzalez@gmail.com>
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.