AI-XGBoost
view release on metacpan or search on metacpan
192021222324252627282930313233343536373839other entities that control, are controlled by, or are under common
control
with
that entity. For the purposes of this definition,
"control"
means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You"
(or
"Your"
) shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source"
form shall mean the preferred form
for
making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object"
form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work"
shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
lib/AI/XGBoost/CAPI.pm view on Meta::CPAN
39404142434445464748495051525354555657585960616263646566676869707172737475our
$VERSION
=
'0.11'
;
# VERSION
# ABSTRACT: Perl wrapper for XGBoost C API https://github.com/dmlc/xgboost
sub
XGDMatrixCreateFromFile {
my
(
$filename
,
$silent
) =
@_
;
$silent
//= 1;
my
$matrix
= 0;
my
$error
= AI::XGBoost::CAPI::RAW::XGDMatrixCreateFromFile(
$filename
,
$silent
, \
$matrix
);
_CheckCall(
$error
);
return
$matrix
;
}
sub
XGDMatrixCreateFromMat {
my
(
$data
,
$missing
) =
@_
;
$missing
//=
"NaN"
;
# TODO Support simple arrays
# TODO Support PDL
# TODO ¿Adapters?
my
$data_adapter
= [
map
{
@$_
}
@$data
];
my
$nrows
=
scalar
@$data
;
my
$ncols
=
scalar
@{
$data
->[0] };
my
$matrix
= 0;
my
$error
= AI::XGBoost::CAPI::RAW::XGDMatrixCreateFromMat(
$data_adapter
,
$nrows
,
$ncols
,
$missing
, \
$matrix
);
_CheckCall(
$error
);
return
$matrix
;
}
sub
XGDMatrixNumRow {
my
(
$matrix
) =
@_
;
my
$rows
= 0;
_CheckCall( AI::XGBoost::CAPI::RAW::XGDMatrixNumRow(
$matrix
, \
$rows
) );
return
$rows
;
}
lib/AI/XGBoost/CAPI.pm view on Meta::CPAN
111112113114115116117118119120121122123124125126127128129130131132133sub
XGDMatrixSaveBinary {
my
(
$matrix
,
$filename
,
$silent
) =
@_
;
$silent
//= 1;
_CheckCall( AI::XGBoost::CAPI::RAW::XGDMatrixSaveBinary(
$matrix
,
$filename
,
$silent
) );
}
sub
XGDMatrixSliceDMatrix {
my
(
$matrix
,
$list_of_indices
) =
@_
;
my
$new_matrix
= 0;
my
$error
= AI::XGBoost::CAPI::RAW::XGDMatrixSliceDMatrix(
$matrix
,
$list_of_indices
,
scalar
@$list_of_indices
,
\
$new_matrix
);
_CheckCall(
$error
);
return
$new_matrix
;
}
sub
XGDMatrixFree {
my
(
$matrix
) =
@_
;
_CheckCall( AI::XGBoost::CAPI::RAW::XGDMatrixFree(
$matrix
) );
return
();
}
sub
XGBoosterCreate {
lib/AI/XGBoost/CAPI.pm view on Meta::CPAN
291292293294295296297298299300301302303304305306307308309310311312
return
();
}
# _CheckCall
#
# Check return code and if necesary, launch an exception
#
sub
_CheckCall {
my
(
$return_code
) =
@_
;
if
(
$return_code
) {
my
$error_message
= AI::XGBoost::CAPI::RAW::XGBGetLastError();
XGBoostException->throw(
error
=>
$error_message
);
}
}
1;
__END__
=pod
=encoding utf-8
lib/AI/XGBoost/CAPI.pm view on Meta::CPAN
342343344345346347348349350351352353354355356357358359360361XGBoosterFree(
$booster
);
XGDMatrixFree(
$dtrain
);
XGDMatrixFree(
$dtest
);
=head1 DESCRIPTION
Perlified wrapper for the C API
=head2 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 L<Exception::Class>
=head1 FUNCTIONS
=head2 XGDMatrixCreateFromFile
Load a data matrix
Parameters:
lib/AI/XGBoost/CAPI/RAW.pm view on Meta::CPAN
142143144145146147148149150151152153154155156157158159160161162163164165166167168169170=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
( run in 0.476 second using v1.01-cache-2.11-cpan-94b05bcf43c )