Add validate_features option for Booster predict (#3323)

* Add validate_features option for Booster predict

* Fix trailing whitespace in docstring
This commit is contained in:
Kristian Gampong 2018-05-29 11:40:49 -07:00 committed by Philip Hyunsu Cho
parent b018ef104f
commit a510e68dda

View File

@ -988,7 +988,8 @@ class Booster(object):
return self.eval_set([(data, name)], iteration)
def predict(self, data, output_margin=False, ntree_limit=0, pred_leaf=False,
pred_contribs=False, approx_contribs=False, pred_interactions=False):
pred_contribs=False, approx_contribs=False, pred_interactions=False,
validate_features=True):
"""
Predict with data.
@ -1030,6 +1031,10 @@ class Booster(object):
pred_contribs), and the sum of the entire matrix equals the raw untransformed margin
value of the prediction. Note the last row and column correspond to the bias term.
validate_features : bool
When this is True, validate that the Booster's and data's feature_names are identical.
Otherwise, it is assumed that the feature_names are the same.
Returns
-------
prediction : numpy array
@ -1046,7 +1051,8 @@ class Booster(object):
if pred_interactions:
option_mask |= 0x10
self._validate_features(data)
if validate_features:
self._validate_features(data)
length = c_bst_ulong()
preds = ctypes.POINTER(ctypes.c_float)()