Skip to content

Instantly share code, notes, and snippets.

@benoitdescamps
benoitdescamps / SHXGBEstimator_illustration
Created May 8, 2018 16:46
code snippet for Tuning Hyperparameters (part I): SuccessiveHalving
class SHXGBEstimator(SHBaseEstimator):
def __init__(self,model):
self.model = model
self.env = {'best_score':-np.infty,'best_iteration':-1,'earlier_stop':False}
def update(self,Xtrain,ytrain,Xval,yval,scoring,n_iterations):
dtrain = DMatrix(data=Xtrain,label=ytrain)
for i in range(n_iterations-self.model.n_estimators):
# note:
# this is a get, but the internal booster in XGBClassifier is also updated
# add unit test for controle if future updates
@benoitdescamps
benoitdescamps / SHBaseEstimator_illustration
Created May 8, 2018 16:45
code snippet for Tuning Hyperparameters (part I): SuccessiveHalving
class SHBaseEstimator(ABC):
def __init__(self,model):
self.model = model
self.env = None
def fit(self,X,y):
self.model.fit(X,y)
def predict(self,X):
return self.model.predict(X)