You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to track the model performance on an eval set that is provided from outside and early stop the tree building based upon the result?
Currently there is the option of validation_fraction along with n_iter_no_change available in the implementation
The issue with that approach:
Cannot use k-fold cross-validation.
Canont use custom metrics
Currently I solve it using the following, which is kind of hacky
#create a gradient boostergbc=GradientBoostingClassifier()
#define the metric function that you want to use to early stoppingdefaccuracy(y_true, y_preds):
return#return the metric output here#This class along with the monitor argument will enable early stoppingclassearly_stopping_gbc():
def__init__(self, accuracy, eval_set, early_stopping_rounds=20):
self.accuracy=accuracyself.x_val=eval_set[0]
self.y_val=eval_set[1]
self.best_perf=0.self.counter=0self.early_stopping_rounds=early_stopping_roundsdef__call__(self,i, model, local_vars):
forcounter, predsinenumerate(model.staged_predict_proba(self.x_val)):
ifcounter==i:
breakacc=self.accuracy(self.y_val,preds[:,1])
ifacc>self.best_perf:
self.best_perf=accself.counter=0else:
self.counter+=1returnself.counter>self.early_stopping_rounds#Run gradient booster with early stopping on 20 roundsgbc.fit(X_train,y_train, monitor=early_stopping_gbc(accuracy, [X_val,y_val], early_stopping_rounds=20))
The text was updated successfully, but these errors were encountered:
How to track the model performance on an eval set that is provided from outside and early stop the tree building based upon the result?
Currently there is the option of
validation_fraction
along withn_iter_no_change
available in the implementationThe issue with that approach:
Currently I solve it using the following, which is kind of hacky
The text was updated successfully, but these errors were encountered: