Custom Python Model XGBoost Training Error

Brenna
Level 1
Custom Python Model XGBoost Training Error

Hello,

I trained a Custom Python model with the XGBoost code sample using the built-in env but got an error, "Coefficients are not defined for Booster type gbtree". Please find details in the attached images.

Do I need to install any package or update anything?

Thanks!

Capture1.PNG

Capture2.PNG


Operating system used: Windows 10

โ€ƒโ€ƒ

0 Kudos
2 Replies
AlexandreL
Dataiker

Hi, 

This is indeed a bug that is planned to be fixed in the next DSS version. In the meantime, you can use this code sample as a workaround

from sklearn.base import BaseEstimator
import xgboost as xgb


class DSSXGBRegressor(BaseEstimator):
	
	def __init__(self,  **kwargs):      
		self.clf = xgb.XGBRegressor(**kwargs)
		
	def fit(self, X, y):
		self.clf.fit(X,y)
		
	def predict(self, X):
		return self.clf.predict(X)
	
	def get_params(self, deep=False):
		return self.clf.get_params(deep)


clf =  DSSXGBRegressor(booster='gblinear', gamma=0, max_depth=6, min_child_weight=1)
0 Kudos
Brenna
Level 1
Author

Hi Alex,

Thank you for your answer. I copied and pasted your code sample but got a PicklingError:

PicklingError: Can't pickle <class 'DSSXGBRegressor'>: it's not found as __builtin__.DSSXGBRegressor

 

Best,

Boren

 

0 Kudos

Labels

?

Setup info

?
A banner prompting to get Dataiku