diff --git a/src/PyClassifiers/XGBoost.cc b/src/PyClassifiers/XGBoost.cc index 7d9476e..a073b1a 100644 --- a/src/PyClassifiers/XGBoost.cc +++ b/src/PyClassifiers/XGBoost.cc @@ -1,16 +1,11 @@ #include "XGBoost.h" - - - //See https ://stackoverflow.com/questions/36071672/using-xgboost-in-c - - - - - - namespace pywrap { + XGBoost::XGBoost() : PyClassifier("xgboost", "XGBClassifier") + { + validHyperparameters = { "tree_method", "early_stopping_rounds", "n_jobs" }; + } std::string XGBoost::version() { return callMethodString("1.0"); diff --git a/src/PyClassifiers/XGBoost.h b/src/PyClassifiers/XGBoost.h index aaf996f..b384ded 100644 --- a/src/PyClassifiers/XGBoost.h +++ b/src/PyClassifiers/XGBoost.h @@ -5,7 +5,7 @@ namespace pywrap { class XGBoost : public PyClassifier { public: - XGBoost() : PyClassifier("xgboost", "XGBClassifier") {}; + XGBoost(); ~XGBoost() = default; std::string version(); }; diff --git a/tests/TestPythonClassifiers.cc b/tests/TestPythonClassifiers.cc index 220f007..6c0b45a 100644 --- a/tests/TestPythonClassifiers.cc +++ b/tests/TestPythonClassifiers.cc @@ -8,8 +8,10 @@ #include "STree.h" #include "SVC.h" #include "RandomForest.h" +#include "XGBoost.h" #include "ODTE.h" #include "TestUtils.h" +#include TEST_CASE("Test Python Classifiers score", "[PyClassifiers]") { @@ -71,4 +73,14 @@ TEST_CASE("Get num features & num edges", "[PyClassifiers]") clf.fit(raw.Xt, raw.yt, raw.featurest, raw.classNamet, raw.statest); REQUIRE(clf.getNumberOfNodes() == 10); REQUIRE(clf.getNumberOfEdges() == 10); +} +TEST_CASE("XGBoost", "[PyClassifiers]") +{ + auto raw = RawDatasets("iris", true); + auto clf = pywrap::XGBoost(); + clf.fit(raw.Xt, raw.yt, raw.featurest, raw.classNamet, raw.statest); + nlohmann::json hyperparameters = { "n_jobs=1" }; + clf.setHyperparameters(hyperparameters); + auto score = clf.score(raw.Xt, raw.yt); + REQUIRE(score == Catch::Approx(0.98).epsilon(raw.epsilon)); } \ No newline at end of file