Skip to content

Commit

Permalink
Gradient boosting - fix test according to xgboost's get_params changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Jan 10, 2023
1 parent 400d288 commit fb45b0c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 46 deletions.
93 changes: 49 additions & 44 deletions Orange/widgets/model/tests/test_owgradientboosting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import unittest
import sys
from typing import Type
Expand Down Expand Up @@ -157,37 +158,39 @@ def test_default_parameters_cls(self):
booster = XGBClassifier()
model = booster(data)
params = model.skl_model.get_params()
booster_params = json.loads(model.skl_model.get_booster().save_config())
updater = booster_params["learner"]["gradient_booster"]["updater"]
tp = updater["grow_colmaker"]["train_param"]
self.assertEqual(params["n_estimators"], self.editor.n_estimators)
self.assertEqual(round(params["learning_rate"], 1),
self.editor.learning_rate)
self.assertEqual(params["max_depth"], self.editor.max_depth)
self.assertEqual(params["reg_lambda"], self.editor.lambda_)
self.assertEqual(params["subsample"], self.editor.subsample)
self.assertEqual(params["colsample_bytree"],
self.editor.colsample_bytree)
self.assertEqual(params["colsample_bylevel"],
self.editor.colsample_bylevel)
self.assertEqual(params["colsample_bynode"],
self.editor.colsample_bynode)
self.assertEqual(
round(float(tp["learning_rate"]), 1), self.editor.learning_rate
)
self.assertEqual(int(tp["max_depth"]), self.editor.max_depth)
self.assertEqual(float(tp["reg_lambda"]), self.editor.lambda_)
self.assertEqual(int(tp["subsample"]), self.editor.subsample)
self.assertEqual(int(tp["colsample_bytree"]), self.editor.colsample_bytree)
self.assertEqual(int(tp["colsample_bylevel"]), self.editor.colsample_bylevel)
self.assertEqual(int(tp["colsample_bynode"]), self.editor.colsample_bynode)

@unittest.skipIf(XGBRegressor is None, "Missing 'xgboost' package")
def test_default_parameters_reg(self):
data = Table("housing")
booster = XGBRegressor()
model = booster(data)
params = model.skl_model.get_params()
booster_params = json.loads(model.skl_model.get_booster().save_config())
updater = booster_params["learner"]["gradient_booster"]["updater"]
tp = updater["grow_colmaker"]["train_param"]
self.assertEqual(params["n_estimators"], self.editor.n_estimators)
self.assertEqual(round(params["learning_rate"], 1),
self.editor.learning_rate)
self.assertEqual(params["max_depth"], self.editor.max_depth)
self.assertEqual(params["reg_lambda"], self.editor.lambda_)
self.assertEqual(params["subsample"], self.editor.subsample)
self.assertEqual(params["colsample_bytree"],
self.editor.colsample_bytree)
self.assertEqual(params["colsample_bylevel"],
self.editor.colsample_bylevel)
self.assertEqual(params["colsample_bynode"],
self.editor.colsample_bynode)
self.assertEqual(
round(float(tp["learning_rate"]), 1), self.editor.learning_rate
)
self.assertEqual(int(tp["max_depth"]), self.editor.max_depth)
self.assertEqual(float(tp["reg_lambda"]), self.editor.lambda_)
self.assertEqual(int(tp["subsample"]), self.editor.subsample)
self.assertEqual(int(tp["colsample_bytree"]), self.editor.colsample_bytree)
self.assertEqual(int(tp["colsample_bylevel"]), self.editor.colsample_bylevel)
self.assertEqual(int(tp["colsample_bynode"]), self.editor.colsample_bynode)


class TestXGBRFLearnerEditor(BaseEditorTest):
Expand Down Expand Up @@ -220,37 +223,39 @@ def test_default_parameters_cls(self):
booster = XGBRFClassifier()
model = booster(data)
params = model.skl_model.get_params()
booster_params = json.loads(model.skl_model.get_booster().save_config())
updater = booster_params["learner"]["gradient_booster"]["updater"]
tp = updater["grow_colmaker"]["train_param"]
self.assertEqual(params["n_estimators"], self.editor.n_estimators)
self.assertEqual(round(params["learning_rate"], 1),
self.editor.learning_rate)
self.assertEqual(params["max_depth"], self.editor.max_depth)
self.assertEqual(params["reg_lambda"], self.editor.lambda_)
self.assertEqual(params["subsample"], self.editor.subsample)
self.assertEqual(params["colsample_bytree"],
self.editor.colsample_bytree)
self.assertEqual(params["colsample_bylevel"],
self.editor.colsample_bylevel)
self.assertEqual(params["colsample_bynode"],
self.editor.colsample_bynode)
self.assertEqual(
round(float(tp["learning_rate"]), 1), self.editor.learning_rate
)
self.assertEqual(int(tp["max_depth"]), self.editor.max_depth)
self.assertEqual(float(tp["reg_lambda"]), self.editor.lambda_)
self.assertEqual(int(tp["subsample"]), self.editor.subsample)
self.assertEqual(int(tp["colsample_bytree"]), self.editor.colsample_bytree)
self.assertEqual(int(tp["colsample_bylevel"]), self.editor.colsample_bylevel)
self.assertEqual(int(tp["colsample_bynode"]), self.editor.colsample_bynode)

@unittest.skipIf(XGBRFRegressor is None, "Missing 'xgboost' package")
def test_default_parameters_reg(self):
data = Table("housing")
booster = XGBRFRegressor()
model = booster(data)
params = model.skl_model.get_params()
booster_params = json.loads(model.skl_model.get_booster().save_config())
updater = booster_params["learner"]["gradient_booster"]["updater"]
tp = updater["grow_colmaker"]["train_param"]
self.assertEqual(params["n_estimators"], self.editor.n_estimators)
self.assertEqual(round(params["learning_rate"], 1),
self.editor.learning_rate)
self.assertEqual(params["max_depth"], self.editor.max_depth)
self.assertEqual(params["reg_lambda"], self.editor.lambda_)
self.assertEqual(params["subsample"], self.editor.subsample)
self.assertEqual(params["colsample_bytree"],
self.editor.colsample_bytree)
self.assertEqual(params["colsample_bylevel"],
self.editor.colsample_bylevel)
self.assertEqual(params["colsample_bynode"],
self.editor.colsample_bynode)
self.assertEqual(
round(float(tp["learning_rate"]), 1), self.editor.learning_rate
)
self.assertEqual(int(tp["max_depth"]), self.editor.max_depth)
self.assertEqual(float(tp["reg_lambda"]), self.editor.lambda_)
self.assertEqual(int(tp["subsample"]), self.editor.subsample)
self.assertEqual(int(tp["colsample_bytree"]), self.editor.colsample_bytree)
self.assertEqual(int(tp["colsample_bylevel"]), self.editor.colsample_bylevel)
self.assertEqual(int(tp["colsample_bynode"]), self.editor.colsample_bynode)


class TestCatGBLearnerEditor(BaseEditorTest):
Expand Down
2 changes: 1 addition & 1 deletion conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ requirements:
- requests
- matplotlib-base >=3.2.0
- openTSNE >=0.6.1
- pandas >=1.3.0,!=1.5.0
- pandas >=1.4.0,!=1.5.0
- pyyaml
- orange-canvas-core >=0.1.28,<0.2a
- orange-widget-base >=4.19.0
Expand Down
2 changes: 1 addition & 1 deletion requirements-opt.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
catboost!=1.0.0 # 1.0.0 segfaults on Macs
xgboost
xgboost>=1.5.0
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ deps =
# oldest: pyyaml
# oldest: openpyxl
oldest: httpx==0.21.0
oldest: xgboost==1.5.0

commands_pre =
# Verify installed packages have compatible dependencies
Expand Down

0 comments on commit fb45b0c

Please sign in to comment.