Early stopping with Keras and sklearn GridSearchCV cross-validation

前端 未结 4 1562
花落未央
花落未央 2020-12-13 04:58

I wish to implement early stopping with Keras and sklean\'s GridSearchCV.

The working code example below is modified from How to Grid Search Hyperparame

4条回答
  •  失恋的感觉
    2020-12-13 05:19

    Here is how to do it with only a single split.

    fit_params['cl__validation_data'] = (X_val, y_val)
    X_final = np.concatenate((X_train, X_val))
    y_final = np.concatenate((y_train, y_val))
    splits = [(range(len(X_train)), range(len(X_train), len(X_final)))]
    
    GridSearchCV(estimator=model, param_grid=param_grid, cv=splits)I
    

    If you want more splits, you can use 'cl__validation_split' with a fixed ratio and construct splits that meet that criteria.

    It might be too paranoid, but I don't use the early stopping data set as a validation data set since it was indirectly used to create the model.

    I also think if you are using early stopping with your final model, then it should also be done when you are doing hyper-parameter search.

提交回复
热议问题