6
$\begingroup$

Is there an easy and efficient way to use XGBoost from within Mathematica without naively Import/Exporting the data? Does anyone know of a third party package or any example applications of integrating with XGBoost?

Details:

$\endgroup$
3
$\begingroup$
Needs["JLink`"]
SetOptions[InstallJava, JVMArguments -> "-Xmx3g"];

Needs["RLink`"]
InstallR["RHomeLocation" -> "C:\\R\\R-3.4.4"]
REvaluate["library(\"xgboost\")"]

{"xgboost", "stats", "graphics", "grDevices", "utils", "datasets", "methods", "base"}

SeedRandom[0];
RSet["x", RandomReal[{-1, 1}, {1000, 50}]];
RSet["y", N@RandomInteger[{0, 1}, 1000]];

REvaluate["set.seed(0)"];
REvaluate["bst<-xgboost(
       data=x,
       label=y,
       booster=\"gbtree\",
       nthread=4,
       objective=\"binary:logistic\",
       eval_metric=\"auc\",
       nround=559,
       max_depth=5,
       eta=0.02,
       subsample=0.7,
       colsample=0.7
       )"];

RSet["z", RandomReal[{-1, 1}, {5, 50}]];
REvaluate["predict(bst,z,ntreelimit=559)"]

{0.608143, 0.677535, 0.4781, 0.60045, 0.502672}

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.