Early stopping with Keras and sklearn GridSearchCV cross-validation

前端 未结 4 1569
花落未央
花落未央 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:14

    [Old answer, before the question was edited & clarified - see updated & accepted answer above]

    I am not sure I have understood your exact issue (your question is quite unclear, and you include many unrelated details, which is never good when asking a SO question - see here).

    You don't have to (and actually should not) include any arguments about validation data in your model = KerasClassifier() function call (it is interesting why you don't feel the same need for training data here, too). Your grid.fit() will take care of both the training and validation folds. So provided that you want to keep the hyperparameter values as included in your example, this function call should be simply

    model = KerasClassifier(build_fn=create_model, 
                            epochs=100, batch_size=32,
                            shuffle=True,
                            verbose=1)
    

    You can see some clear and well-explained examples regarding the use of GridSearchCV with Keras here.

提交回复
热议问题