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

Prevent training without setting up caches. #4066

Merged
merged 2 commits into from
Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/python/python_intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ A saved model can be loaded as follows:
bst = xgb.Booster({'nthread': 4}) # init model
bst.load_model('model.bin') # load data

Methods including `update` and `boost` from `xgboost.Booster` are designed for
internal usage only. The wrapper function `xgboost.train` does some
pre-configuration including setting up caches and some other parameters.

Early Stopping
--------------
If you have a validation set, you can use early stopping to find the optimal number of boosting rounds.
Expand Down Expand Up @@ -215,4 +219,3 @@ When you use ``IPython``, you can use the :py:meth:`xgboost.to_graphviz` functio
.. code-block:: python

xgb.to_graphviz(bst, num_trees=2)

11 changes: 7 additions & 4 deletions python-package/xgboost/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,8 @@ def set_param(self, params, value=None):
_check_call(_LIB.XGBoosterSetParam(self.handle, c_str(key), c_str(str(val))))

def update(self, dtrain, iteration, fobj=None):
"""
Update for one iteration, with objective function calculated internally.
"""Update for one iteration, with objective function calculated
internally. This function should not be called directly by users.

Parameters
----------
Expand All @@ -1052,6 +1052,7 @@ def update(self, dtrain, iteration, fobj=None):
Current iteration number.
fobj : function
Customized objective function.

"""
if not isinstance(dtrain, DMatrix):
raise TypeError('invalid training matrix: {}'.format(type(dtrain).__name__))
Expand All @@ -1066,8 +1067,9 @@ def update(self, dtrain, iteration, fobj=None):
self.boost(dtrain, grad, hess)

def boost(self, dtrain, grad, hess):
"""
Boost the booster for one iteration, with customized gradient statistics.
"""Boost the booster for one iteration, with customized gradient
statistics. Like :func:`xgboost.core.Booster.update`, this
function should not be called directly by users.

Parameters
----------
Expand All @@ -1077,6 +1079,7 @@ def boost(self, dtrain, grad, hess):
The first order of gradient.
hess : list
The second order of gradient.

"""
if len(grad) != len(hess):
raise ValueError('grad / hess length mismatch: {} / {}'.format(len(grad), len(hess)))
Expand Down
2 changes: 2 additions & 0 deletions src/learner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ class LearnerImpl : public Learner {
if (num_feature > mparam_.num_feature) {
mparam_.num_feature = num_feature;
}
CHECK_NE(mparam_.num_feature, 0)
<< "0 feature is supplied. Are you using raw Booster?";
// setup
cfg_["num_feature"] = common::ToString(mparam_.num_feature);
CHECK(obj_ == nullptr && gbm_ == nullptr);
Expand Down