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:
parent
b018ef104f
commit
a510e68dda
@ -988,7 +988,8 @@ class Booster(object):
|
|||||||
return self.eval_set([(data, name)], iteration)
|
return self.eval_set([(data, name)], iteration)
|
||||||
|
|
||||||
def predict(self, data, output_margin=False, ntree_limit=0, pred_leaf=False,
|
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.
|
Predict with data.
|
||||||
|
|
||||||
@ -1030,6 +1031,10 @@ class Booster(object):
|
|||||||
pred_contribs), and the sum of the entire matrix equals the raw untransformed margin
|
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.
|
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
|
Returns
|
||||||
-------
|
-------
|
||||||
prediction : numpy array
|
prediction : numpy array
|
||||||
@ -1046,7 +1051,8 @@ class Booster(object):
|
|||||||
if pred_interactions:
|
if pred_interactions:
|
||||||
option_mask |= 0x10
|
option_mask |= 0x10
|
||||||
|
|
||||||
self._validate_features(data)
|
if validate_features:
|
||||||
|
self._validate_features(data)
|
||||||
|
|
||||||
length = c_bst_ulong()
|
length = c_bst_ulong()
|
||||||
preds = ctypes.POINTER(ctypes.c_float)()
|
preds = ctypes.POINTER(ctypes.c_float)()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user