Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Python documents. #6376

Merged
merged 3 commits into from Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
6 changes: 4 additions & 2 deletions tests/python/test_callback.py
Expand Up @@ -123,9 +123,11 @@ 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,
save_best=True)
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