'How to create a k-Fold cross validation test for ANN model?

I am currently trying to apply k-fold cross validation on my ANN Model by using cross_val_score function on python. However I keep getting this error:

TypeError: estimator should be an estimator implementing 'fit' method, <keras.callbacks.History object at 0x00000168C79FE850> was passed

ANN model:

model = build_model()

# Early Stopping
# The patience parameter is the amount of epochs to check for improvement
early_stop = keras.callbacks.EarlyStopping(monitor='val_loss', patience = 5)

ann_Model = model.fit(normed_train_data, y, epochs=EPOCHS, 
                    validation_split = 0.2, verbose=0, callbacks=[early_stop, PrintDot()])
plot_history(ann_Model)

k-fold cross validation code:

#k-fold cross validation
    
from sklearn.model_selection import cross_val_score, KFold
from sklearn import metrics
    
scores = cross_val_score(ann_Model, X, y, cv = 5, scoring = 'r2')

Any fixes for this issue? Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source