AI-XGBoost
view release on metacpan or search on metacpan
lib/AI/XGBoost/CAPI/RAW.pm view on Meta::CPAN
AI::XGBoost::CAPI::RAW - Perl wrapper for XGBoost C API https://github.com/dmlc/xgboost
=head1 VERSION
version 0.11
=head1 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);
=head1 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
=head1 FUNCTIONS
=head2 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
=head2 XGDMatrixCreateFromFile
Load a data matrix
Parameters:
=over 4
=item filename
the name of the file
=item silent
whether print messages during loading
=item out
a loaded data matrix
=back
=head2 XGDMatrixCreateFromCSREx
Create a matrix content from CSR fromat
Parameters:
=over 4
=item indptr
pointer to row headers
=item indices
findex
=item data
fvalue
=item nindptr
number of rows in the matrix + 1
=item nelem
number of nonzero elements in the matrix
=item num_col
number of columns; when it's set to 0, then guess from data
=item out
created dmatrix
lib/AI/XGBoost/CAPI/RAW.pm view on Meta::CPAN
=back
=head2 XGDMatrixCreateFromMat
Create matrix content from dense matrix
Parameters:
=over 4
=item data
pointer to the data space
=item nrow
number of rows
=item ncol
number columns
=item missing
which value to represent missing value
=item out
created dmatrix
=back
=head2 XGDMatrixCreateFromMat_omp
Create matrix content from dense matrix
Parameters:
=over 4
=item data
pointer to the data space
=item nrow
number of rows
=item ncol
number columns
=item missing
which value to represent missing value
=item out
created dmatrix
=item nthread
number of threads (up to maximum cores available, if <=0 use all cores)
=back
=head2 XGDMatrixSliceDMatrix
Create a new dmatrix from sliced content of existing matrix
Parameters:
=over 4
=item handle
instance of data matrix to be sliced
=item idxset
index set
=item len
length of index set
=item out
a sliced new matrix
=back
=head2 XGDMatrixNumRow
Get number of rows.
Parameters:
=over 4
=item handle
the handle to the DMatrix
=item out
The address to hold number of rows.
=back
=head2 XGDMatrixNumCol
Get number of cols.
Parameters:
=over 4
=item handle
the handle to the DMatrix
=item out
( run in 1.253 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )