From a510e68ddaa1004b1f1e59f67bb43314c398b5e7 Mon Sep 17 00:00:00 2001 From: Kristian Gampong <29646518+airknits@users.noreply.github.com> Date: Tue, 29 May 2018 11:40:49 -0700 Subject: [PATCH] Add validate_features option for Booster predict (#3323) * Add validate_features option for Booster predict * Fix trailing whitespace in docstring --- python-package/xgboost/core.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/python-package/xgboost/core.py b/python-package/xgboost/core.py index 8b5ec7033..724918c51 100644 --- a/python-package/xgboost/core.py +++ b/python-package/xgboost/core.py @@ -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)()