Skip to content

Commit

Permalink
Update Python documents. (#6376)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Nov 12, 2020
1 parent c564518 commit c90f968
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions demo/guide-python/cross_validation.py
Expand Up @@ -14,15 +14,15 @@
# std_value is standard deviation of the metric
xgb.cv(param, dtrain, num_round, nfold=5,
metrics={'error'}, seed=0,
callbacks=[xgb.callback.print_evaluation(show_stdv=True)])
callbacks=[xgb.callback.EvaluationMonitor(show_stdv=True)])

print('running cross validation, disable standard deviation display')
# do cross validation, this will print result out as
# [iteration] metric_name:mean_value
res = xgb.cv(param, dtrain, num_boost_round=10, nfold=5,
metrics={'error'}, seed=0,
callbacks=[xgb.callback.print_evaluation(show_stdv=False),
xgb.callback.early_stop(3)])
callbacks=[xgb.callback.EvaluationMonitor(show_stdv=False),
xgb.callback.EarlyStopping(3)])
print(res)
print('running cross validation, with preprocessing function')
# define the preprocessing function
Expand Down
12 changes: 8 additions & 4 deletions doc/python/python_api.rst
Expand Up @@ -69,13 +69,15 @@ Plotting API

Callback API
------------
.. autofunction:: xgboost.callback.print_evaluation
.. autofunction:: xgboost.callback.TrainingCallback

.. autofunction:: xgboost.callback.record_evaluation
.. autofunction:: xgboost.callback.EvaluationMonitor

.. autofunction:: xgboost.callback.reset_learning_rate
.. autofunction:: xgboost.callback.EarlyStopping

.. autofunction:: xgboost.callback.early_stop
.. autofunction:: xgboost.callback.LearningRateScheduler

.. autofunction:: xgboost.callback.TrainingCheckPoint

.. _dask_api:

Expand All @@ -91,6 +93,8 @@ Dask API

.. autofunction:: xgboost.dask.predict

.. autofunction:: xgboost.dask.inplace_predict

.. autofunction:: xgboost.dask.DaskXGBClassifier

.. autofunction:: xgboost.dask.DaskXGBRegressor
6 changes: 4 additions & 2 deletions python-package/xgboost/sklearn.py
Expand Up @@ -510,7 +510,8 @@ def fit(self, X, y, sample_weight=None, base_margin=None,
.. code-block:: python
[xgb.callback.reset_learning_rate(custom_rates)]
callbacks = [xgb.callback.EarlyStopping(rounds=early_stopping_rounds,
save_best=True)]
"""
self.n_features_in_ = X.shape[1]
Expand Down Expand Up @@ -1249,7 +1250,8 @@ def fit(self, X, y, group, sample_weight=None, base_margin=None,
.. code-block:: python
[xgb.callback.reset_learning_rate(custom_rates)]
callbacks = [xgb.callback.EarlyStopping(rounds=early_stopping_rounds,
save_best=True)]
"""
# check if group information is provided
Expand Down
5 changes: 3 additions & 2 deletions tests/python/test_callback.py
Expand Up @@ -123,9 +123,10 @@ def test_early_stopping_custom_eval_skl(self):
X, y = load_breast_cancer(return_X_y=True)
cls = xgb.XGBClassifier()
early_stopping_rounds = 5
early_stop = xgb.callback.EarlyStopping(rounds=early_stopping_rounds)
cls.fit(X, y, eval_set=[(X, y)],
early_stopping_rounds=early_stopping_rounds,
eval_metric=tm.eval_error_metric)
eval_metric=tm.eval_error_metric,
callbacks=[early_stop])
booster = cls.get_booster()
dump = booster.get_dump(dump_format='json')
assert len(dump) - booster.best_iteration == early_stopping_rounds + 1
Expand Down

0 comments on commit c90f968

Please sign in to comment.