NAME

AI::XGBoost::CAPI - Perl wrapper for XGBoost C API https://github.com/dmlc/xgboost

VERSION

version 0.006

SYNOPSIS

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);

DESCRIPTION

Perlified wrapper for the C API

Error handling

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

FUNCTIONS

XGDMatrixCreateFromFile

Load a data matrix

Parameters:

filename

the name of the file

silent

whether print messages during loading

Returns a loaded data matrix

XGDMatrixCreateFromMat

Create from dense matrix

Parameters:

matrix

matrix data

missing

value indicating missing data (optional)

Returns a loaded data matrix

XGDMatrixNumRow

Get number of rows

Parameters:

matrix

DMatrix

XGDMatrixNumCol

Get number of cols

Parameters:

matrix

DMatrix

XGDMatrixSetFloatInfo

XGDMatrixGetFloatInfo

XGDMatrixFree

Free space in data matrix

Parameters:

matrix

DMatrix to be freed

XGBoosterCreate

Create XGBoost learner

Parameters:

matrices

matrices that are set to be cached

XGBoosterSetParam

XGBoosterSetAttr

XGBoosterGetAttr

XGBoosterGetAttrNames

XGBoosterUpdateOneIter

Update the model in one round using train matrix

Parameters:

booster

XGBoost learner to train

iter

current iteration rounds

train_matrix

training data

XGBoosterBoostOneIter

XGBoosterEvalOneIter

XGBoosterPredict

Make prediction based on train matrix

Parameters:

booster

XGBoost learner

data_matrix

Data matrix with the elements to predict

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

Returns an arrayref with the predictions corresponding to the rows of data matrix

XGBoosterDumpModel

XGBoosterDumpModelEx

XGBoosterDumpModelWithFeatures

XGBoosterDumpModelExWithFeatures

XGBoosterFree

Free booster object

Parameters:

booster

booster to be freed

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