2
votes

I have created a Keras Classifier for k fold validation. Below is the function for building the classifer.

def build_classifier():

classifier = Sequential()
classifier.add(Dense(activation="relu", input_dim=11, units=6, kernel_initializer="uniform"))
classifier.add(Dense(activation="relu", units=6, kernel_initializer="uniform"))
classifier.add(Dense(activation="sigmoid", units=1, kernel_initializer="uniform"))
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

return classifier

I have initialized the classifier as below.

    classfier = KerasClassifier(build_fn = build_classifier, batch_size=10, epochs=100)

I am trying to get the accuracy score from this 10 fold validation.

    accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10, n_jobs = -1)

However it show me a TypeError:

TypeError: If no scoring is specified, the estimator passed should have a 'score' method. The estimator does not.

1
Show the imports. Which version of keras and scikit-learn are you using?Vivek Kumar
keras v2.2.2 and scikit-learn v0.19.1Eva Cheong

1 Answers

0
votes

In cross_val_score pass scoring="accuracy" and it should work.
Similar solved question here: Scikit-learn TypeError: If no scoring is specified, the estimator passed should have a 'score' method