{"id":19700394,"url":"https://github.com/pablrod/p5-ai-xgboost","last_synced_at":"2025-04-29T13:32:13.776Z","repository":{"id":56829903,"uuid":"92767532","full_name":"pablrod/p5-AI-XGBoost","owner":"pablrod","description":"Perl wrapper for XGBoost library","archived":false,"fork":false,"pushed_at":"2017-08-20T21:00:45.000Z","size":90,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-08-20T22:00:46.126Z","etag":null,"topics":["gbm","machine-learning","perl","xgboost"],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pablrod.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-29T19:01:44.000Z","updated_at":"2020-02-13T04:22:42.000Z","dependencies_parsed_at":"2022-09-02T05:50:26.088Z","dependency_job_id":null,"html_url":"https://github.com/pablrod/p5-AI-XGBoost","commit_stats":null,"previous_names":[],"tags_count":10,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablrod%2Fp5-AI-XGBoost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablrod%2Fp5-AI-XGBoost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablrod%2Fp5-AI-XGBoost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablrod%2Fp5-AI-XGBoost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pablrod","download_url":"https://codeload.github.com/pablrod/p5-AI-XGBoost/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224175731,"owners_count":17268390,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gbm","machine-learning","perl","xgboost"],"created_at":"2024-11-11T21:05:48.913Z","updated_at":"2024-11-11T21:05:49.442Z","avatar_url":"https://github.com/pablrod.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nAI::XGBoost - Perl wrapper for XGBoost library [https://github.com/dmlc/xgboost](https://github.com/dmlc/xgboost)\n\n# VERSION\n\nversion 0.11\n\n# SYNOPSIS\n\n```perl\nuse 5.010;\nuse aliased 'AI::XGBoost::DMatrix';\nuse AI::XGBoost qw(train);\n\n# We are going to solve a binary classification problem:\n#  Mushroom poisonous or not\n\nmy $train_data = DMatrix-\u003eFrom(file =\u003e 'agaricus.txt.train');\nmy $test_data = DMatrix-\u003eFrom(file =\u003e 'agaricus.txt.test');\n\n# With XGBoost we can solve this problem using 'gbtree' booster\n#  and as loss function a logistic regression 'binary:logistic'\n#  (Gradient Boosting Regression Tree)\n# XGBoost Tree Booster has a lot of parameters that we can tune\n# (https://github.com/dmlc/xgboost/blob/master/doc/parameter.md)\n\nmy $booster = train(data =\u003e $train_data, number_of_rounds =\u003e 10, params =\u003e {\n        objective =\u003e 'binary:logistic',\n        eta =\u003e 1.0,\n        max_depth =\u003e 2,\n        silent =\u003e 1\n    });\n\n# For binay classification predictions are probability confidence scores in [0, 1]\n#  indicating that the label is positive (1 in the first column of agaricus.txt.test)\nmy $predictions = $booster-\u003epredict(data =\u003e $test_data);\n\nsay join \"\\n\", @$predictions[0 .. 10];\n\nuse aliased 'AI::XGBoost::DMatrix';\nuse AI::XGBoost qw(train);\nuse Data::Dataset::Classic::Iris;\n\n# We are going to solve a multiple classification problem:\n#  determining plant species using a set of flower's measures \n\n# XGBoost uses number for \"class\" so we are going to codify classes\nmy %class = (\n    setosa =\u003e 0,\n    versicolor =\u003e 1,\n    virginica =\u003e 2\n);\n\nmy $iris = Data::Dataset::Classic::Iris::get();\n\n# Split train and test, label and features\nmy $train_dataset = [map {$iris-\u003e{$_}} grep {$_ ne 'species'} keys %$iris];\nmy $test_dataset = [map {$iris-\u003e{$_}} grep {$_ ne 'species'} keys %$iris];\n\nsub transpose {\n# Transposing without using PDL, Data::Table, Data::Frame or other modules\n# to keep minimal dependencies\n    my $array = shift;\n    my @aux = ();\n    for my $row (@$array) {\n        for my $column (0 .. scalar @$row - 1) {\n            push @{$aux[$column]}, $row-\u003e[$column];\n        }\n    }\n    return \\@aux;\n}\n\n$train_dataset = transpose($train_dataset);\n$test_dataset = transpose($test_dataset);\n\nmy $train_label = [map {$class{$_}} @{$iris-\u003e{'species'}}];\nmy $test_label = [map {$class{$_}} @{$iris-\u003e{'species'}}];\n\nmy $train_data = DMatrix-\u003eFrom(matrix =\u003e $train_dataset, label =\u003e $train_label);\nmy $test_data = DMatrix-\u003eFrom(matrix =\u003e $test_dataset, label =\u003e $test_label);\n\n# Multiclass problems need a diferent objective function and the number\n#  of classes, in this case we are using 'multi:softprob' and\n#  num_class =\u003e 3\nmy $booster = train(data =\u003e $train_data, number_of_rounds =\u003e 20, params =\u003e {\n        max_depth =\u003e 3,\n        eta =\u003e 0.3,\n        silent =\u003e 1,\n        objective =\u003e 'multi:softprob',\n        num_class =\u003e 3\n    });\n\nmy $predictions = $booster-\u003epredict(data =\u003e $test_data);\n```\n\n# DESCRIPTION\n\nPerl wrapper for XGBoost library. \n\nThe easiest way to use the wrapper is using `train`, but beforehand \nyou need the data to be used contained in a `DMatrix` object\n\nThis is a work in progress, feedback, comments, issues, suggestion and\npull requests are welcome!!\n\nXGBoost library is used via [Alien::XGBoost](https://metacpan.org/pod/Alien::XGBoost). That means downloading,\ncompiling and installing if it's not available in your system.\n\n# FUNCTIONS\n\n## train\n\nPerforms gradient boosting using the data and parameters passed\n\nReturns a trained AI::XGBoost::Booster used\n\n### Parameters\n\n- params\n\n    Parameters for the booster object. \n\n    Full list available: https://github.com/dmlc/xgboost/blob/master/doc/parameter.md \n\n- data\n\n    AI::XGBoost::DMatrix object used for training\n\n- number\\_of\\_rounds\n\n    Number of boosting iterations\n\n# ROADMAP\n\nThe goal is to make a full wrapper for XGBoost.\n\n## VERSIONS\n\n- 0.2 \n\n    Full C API \"easy\" to use, with PDL support as [AI::XGBoost::CAPI](https://metacpan.org/pod/AI::XGBoost::CAPI)\n\n    Easy means clients don't have to use [FFI::Platypus](https://metacpan.org/pod/FFI::Platypus) or modules dealing\n    with C structures\n\n- 0.25\n\n    Alien package for libxgboost.so/xgboost.dll\n\n- 0.3\n\n    Object oriented API Moose based with DMatrix and Booster classes\n\n- 0.4\n\n    Complete object oriented API\n\n- 0.5\n\n    Use perl signatures ([https://metacpan.org/pod/distribution/perl/pod/perlexperiment.pod#Subroutine-signatures](https://metacpan.org/pod/distribution/perl/pod/perlexperiment.pod#Subroutine-signatures))\n\n# SEE ALSO\n\n- [AI::MXNet](https://metacpan.org/pod/AI::MXNet)\n- [FFI::Platypus](https://metacpan.org/pod/FFI::Platypus)\n- [NativeCall](https://metacpan.org/pod/NativeCall)\n\n# AUTHOR\n\nPablo Rodríguez González \u003cpablo.rodriguez.gonzalez@gmail.com\u003e\n\n# COPYRIGHT AND LICENSE\n\nCopyright (c) 2017 by Pablo Rodríguez González.\n\n# CONTRIBUTOR\n\nRuben \u003cme@ruben.tech\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablrod%2Fp5-ai-xgboost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpablrod%2Fp5-ai-xgboost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablrod%2Fp5-ai-xgboost/lists"}