1
$\begingroup$

I have a binary feature {0, 1} and only when its value is 1, I would like my XGBoost model to "evaluate" a set of trees. The goal is to save on prediction time by not evaluating a set of trees when the binary feature's value is 0.

So I was thinking if this feature is the root node of those trees, with rest of the tree being the subtree on the value of 1 of this feature, I may achieve my goal.

Is it possible to tweak XGBoost model in such a way?

$\endgroup$

1 Answer 1

2
$\begingroup$

It would be best to add that as control logic outside of the model.

If you were using Python, it would be something like:

from xgboost import XGBClassifier

model = XGBClassifier()
model.fit(X_train, y_train)

if feature == 1:
    y = model.predict(X)
else feature == 0:
    print("No prediciton made.")
$\endgroup$
1
  • 1
    $\begingroup$ Thanks for your answer @Brian Spiering. This would be my last resort if the model itself can't support it. I made my preference for the model itself to support it because our workplace's software doesn't support "ensembling" like in your answer. $\endgroup$
    – Nitin
    Commented Jul 5, 2022 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.