Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: The model is not configured to compute accuracy

When using this code I got from some tutorial I got the error that says The model is not configured to compute accuracy and that I should pass accuracy , The weird part is I am already passing metrics = ['accuracy']

I've searched a lot and all the codes I have seen works fine except mine.

Evaluating the ANN

from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import cross_val_score
from tensorflow.python.keras.models import Sequential #Used to initialize the NN
from tensorflow.python.keras.layers import Dense #Used to create the layers in the ANN

def build_classifier():
    classifier = Sequential()
    classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu',input_dim = 11))
    classifier.add(Dense(units= 6, kernel_initializer = 'uniform', activation = 'relu'))
    classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))
    classifier.compile(optimizer='adam', loss='binary_crossentropy', metrics= ['accuracy'])
    return classifier
# Needs to be revised from evaluting video in the course if needed
classifier = KerasClassifier(build_fn = build_classifier, batch_size = 10, nb_epoch = 100)
accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10, n_jobs = -1)

I expect the output to be the accuarcies vector, instead i got:

ValueError: The model is not configured to compute accuracy. You should pass metrics=["accuracy"] to the model.compile() method.

like image 917
Abdelrahman Emam Avatar asked Jul 11 '19 19:07

Abdelrahman Emam


1 Answers

Changing the parameter from metrics=['accuracy'] by metrics=['acc'] works for me.

Regards, Joseph

like image 74
Joseph BERTHE Avatar answered Nov 02 '22 23:11

Joseph BERTHE