AI-XGBoost
view release on metacpan or search on metacpan
lib/AI/XGBoost/Booster.pm view on Meta::CPAN
# XGBoost Tree Booster has a lot of parameters that we can tune
# (https://github.com/dmlc/xgboost/blob/master/doc/parameter.md)
my $booster = train(data => $train_data, number_of_rounds => 10, params => {
objective => 'binary:logistic',
eta => 1.0,
max_depth => 2,
silent => 1
});
# For binay classification predictions are probability confidence scores in [0, 1]
# indicating that the label is positive (1 in the first column of agaricus.txt.test)
my $predictions = $booster->predict(data => $test_data);
say join "\n", @$predictions[0 .. 10];
=head1 DESCRIPTION
Booster objects control training, prediction and evaluation
Work In Progress, the API may change. Comments and suggestions are welcome!
=head1 METHODS
=head2 update
Update one iteration
=head3 Parameters
=over 4
=item iteration
Current iteration number
=item dtrain
Training data (AI::XGBoost::DMatrix)
=back
=head2 boost
Boost one iteration using your own gradient
=head3 Parameters
=over 4
=item dtrain
Training data (AI::XGBoost::DMatrix)
=item grad
Gradient of your objective function (Reference to an array)
=item hess
Hessian of your objective function, that is, second order gradient (Reference to an array)
=back
=head2 predict
Predict data using the trained model
=head3 Parameters
=over 4
=item data
Data to predict
=back
=head2 set_param
Set booster parameter
=head3 Example
$booster->set_param('objective', 'binary:logistic');
=head2 set_attr
Set a string attribute
=head2 get_attr
Get a string attribute
=head2 get_score
Get importance of each feature
=head3 Parameters
=over 4
=item importance_type
Type of importance. Valid values:
=over 4
=item weight
Number of times a feature is used to split the data across all trees
=item gain
Average gain of the feature when it is used in trees
=item cover
Average coverage of the feature when it is used in trees
=back
( run in 2.416 seconds using v1.01-cache-2.11-cpan-364913b4093 )