Skip to content

Commit

Permalink
Merge pull request dmlc#868 from catena/master
Browse files Browse the repository at this point in the history
minor fix: in sklearn.py return attribute best_ntree_limit if early stopped
  • Loading branch information
terrytangyuan committed Feb 25, 2016
2 parents cdbafaf + 790dc87 commit 319091b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions python-package/xgboost/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ def fit(self, X, y, eval_set=None, eval_metric=None,
Requires at least one item in evals. If there's more than one,
will use the last. Returns the model from the last iteration
(not the best one). If early stopping occurs, the model will
have two additional fields: bst.best_score and bst.best_iteration.
have three additional fields: bst.best_score, bst.best_iteration
and bst.best_ntree_limit.
(Use bst.best_ntree_limit to get the correct value if num_parallel_tree
and/or num_class appears in the parameters)
verbose : bool
If `verbose` and an evaluation set is used, writes the evaluation
metric measured on the validation set to stderr.
Expand Down Expand Up @@ -251,6 +254,7 @@ def fit(self, X, y, eval_set=None, eval_metric=None,
if early_stopping_rounds is not None:
self.best_score = self._Booster.best_score
self.best_iteration = self._Booster.best_iteration
self.best_ntree_limit = self._Booster.best_ntree_limit
return self

def predict(self, data, output_margin=False, ntree_limit=0):
Expand Down Expand Up @@ -349,7 +353,10 @@ def fit(self, X, y, sample_weight=None, eval_set=None, eval_metric=None,
Requires at least one item in evals. If there's more than one,
will use the last. Returns the model from the last iteration
(not the best one). If early stopping occurs, the model will
have two additional fields: bst.best_score and bst.best_iteration.
have three additional fields: bst.best_score, bst.best_iteration
and bst.best_ntree_limit.
(Use bst.best_ntree_limit to get the correct value if num_parallel_tree
and/or num_class appears in the parameters)
verbose : bool
If `verbose` and an evaluation set is used, writes the evaluation
metric measured on the validation set to stderr.
Expand Down Expand Up @@ -416,6 +423,7 @@ def fit(self, X, y, sample_weight=None, eval_set=None, eval_metric=None,
if early_stopping_rounds is not None:
self.best_score = self._Booster.best_score
self.best_iteration = self._Booster.best_iteration
self.best_ntree_limit = self._Booster.best_ntree_limit

return self

Expand Down

0 comments on commit 319091b

Please sign in to comment.