Created
May 8, 2018 16:46
-
-
Save benoitdescamps/be6cb6f271ea38c5af4cba498c0bd9b4 to your computer and use it in GitHub Desktop.
code snippet for Tuning Hyperparameters (part I): SuccessiveHalving
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
self.model.get_booster().update(dtrain,iteration=self.model.n_estimators) | |
self.model.n_estimators += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment