'How to write a custom wrapper for a prediction function in xgboost or other estimators
So I want to manipulate the result of my prediction and I need to do it within the estimator. I tried to write a wrapper like this, but my kernel just dies when I execute the predict function. From my understanding this should just replace the predict function in xgboost right?
from xgboost import XGBRegressor as xgb
class custXGB(xgb):
def predict(self, X, y=None):
return self.predict(X)
I then fit the clas normally but when I use predict the kernel dies without error:
estimator = custXGB()
estimator.fit(X_train, y_train)
# works fine
estimator.predict(X_train)
#kernel dies
Solution 1:[1]
You've written an infinite loop: your predict
is calling itself, not the XGBRegressor.predict
. Replace self
with super()
inside the method.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ben Reiniger |