I'm using KerasClassifier from sklearn to wrap my Keras model in order to perform K-fold cross validation.
model = KerasClassifier(build_fn=create_model, epochs=20, batch_size=8, verbose = 1)
kfold = KFold(n_splits=10)
scoring = ['accuracy', 'precision', 'recall', 'f1']
results = cross_validate(estimator=model,
X=x_train,
y=y_train,
cv=kfold,
scoring=scoring,
return_train_score=True,
return_estimator=True)
Then I choose the best model between the 10 estimators returned by the function, according to metrics:
best_model = results['estimators'][2] #for example the second model
Now, I want to perform a predict on x_test and get accuracy and loss metrics. How can I do it? I tried model.evaluate(x_test, y_test)
but the model is a KerasClassifier so I get an error.