Skip to content

Commit

Permalink
Let XGBoostError inherit ValueError. (#5696)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis authored May 26, 2020
1 parent 8438c7d commit f145241
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion python-package/xgboost/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
c_bst_ulong = ctypes.c_uint64


class XGBoostError(Exception):
class XGBoostError(ValueError):
"""Error thrown by xgboost trainer."""


Expand Down
34 changes: 14 additions & 20 deletions python-package/xgboost/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,16 +537,13 @@ def fit(self, X, y, sample_weight=None, base_margin=None,
else:
params.update({'eval_metric': eval_metric})

try:
self._Booster = train(params, train_dmatrix,
self.get_num_boosting_rounds(), evals=evals,
early_stopping_rounds=early_stopping_rounds,
evals_result=evals_result,
obj=obj, feval=feval,
verbose_eval=verbose, xgb_model=xgb_model,
callbacks=callbacks)
except XGBoostError as e:
raise ValueError(e)
self._Booster = train(params, train_dmatrix,
self.get_num_boosting_rounds(), evals=evals,
early_stopping_rounds=early_stopping_rounds,
evals_result=evals_result,
obj=obj, feval=feval,
verbose_eval=verbose, xgb_model=xgb_model,
callbacks=callbacks)

if evals_result:
for val in evals_result.items():
Expand Down Expand Up @@ -1230,16 +1227,13 @@ def _dmat_init(group, **params):
'Custom evaluation metric is not yet supported for XGBRanker.')
params.update({'eval_metric': eval_metric})

try:
self._Booster = train(params, train_dmatrix,
self.n_estimators,
early_stopping_rounds=early_stopping_rounds,
evals=evals,
evals_result=evals_result, feval=feval,
verbose_eval=verbose, xgb_model=xgb_model,
callbacks=callbacks)
except XGBoostError as e:
raise ValueError(e)
self._Booster = train(params, train_dmatrix,
self.n_estimators,
early_stopping_rounds=early_stopping_rounds,
evals=evals,
evals_result=evals_result, feval=feval,
verbose_eval=verbose, xgb_model=xgb_model,
callbacks=callbacks)

self.objective = params["objective"]

Expand Down

0 comments on commit f145241

Please sign in to comment.