Skip to content

Commit

Permalink
Attribute error.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Jan 11, 2021
1 parent 157fcf4 commit e97749b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion python-package/xgboost/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,10 @@ def predict(
# get ntree_limit to use - if none specified, default to
# best_ntree_limit if defined, otherwise 0.
if ntree_limit is None:
ntree_limit = self.best_ntree_limit
try:
ntree_limit = self.best_ntree_limit
except AttributeError:
ntree_limit = 0
return self.get_booster().predict(
test_dmatrix,
output_margin=output_margin,
Expand Down
6 changes: 5 additions & 1 deletion python-package/xgboost/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ def _train_internal(params, dtrain,

num_groups = int(config['learner']['learner_model_param']['num_class'])
num_groups = 1 if num_groups == 0 else num_groups
bst.best_ntree_limit = ((bst.best_iteration + 1) * num_parallel_tree * num_groups)
bst.set_attr(
"best_ntree_limit",
(bst.best_iteration + 1) * num_parallel_tree * num_groups
)
bst.best_ntree_limit = int(bst.attr("best_ntree_limit"))

# Copy to serialise and unserialise booster to reset state and free
# training memory
Expand Down

0 comments on commit e97749b

Please sign in to comment.