Reputation: 27
I am very new in Deep Learning: I am doing a deep learning course on Udemy. once I execute my code, it says:
ValueError: The model is not configured to compute accuracy. You should pass metrics=["accuracy"]
to the model.compile()
method.
I tried to change 'accuracy' into 'acc', It gives me no more error, but the code is super fast, it shows me only 10 epochs instead of 100. besides I was expecting accuracy around 83% but I am having something like 79%.
can someone please help me?
''''
import keras
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import cross_val_score
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
def build_classifier():
classifier = Sequential()
classifier.add(Dense(6, kernel_initializer='uniform', activation='relu', input_dim= 11))
classifier.add(Dense(6, kernel_initializer='uniform', activation='relu'))
classifier.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
return classifier
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)
'''' This is my fulltraceback:
''''
accuracies = cross_val_score(estimator = classifier, X = x_train, y = y_train, cv=10, n_jobs=-1, verbose=0)
Traceback (most recent call last):
File "<ipython-input-138-36c63e93365e>", line 1, in <module>
accuracies = cross_val_score(estimator = classifier, X = x_train, y = y_train, cv=10, n_jobs=-1, verbose=0)
File "C:\ProgramData\Anaconda3\envs\deeplearning\lib\site-packages\sklearn\model_selection\_validation.py", line 389, in cross_val_score
error_score=error_score)
File "C:\ProgramData\Anaconda3\envs\deeplearning\lib\site-packages\sklearn\model_selection\_validation.py", line 235, in cross_validate
for train, test in cv.split(X, y, groups))
File "C:\ProgramData\Anaconda3\envs\deeplearning\lib\site-packages\joblib\parallel.py", line 1017, in __call__
self.retrieve()
File "C:\ProgramData\Anaconda3\envs\deeplearning\lib\site-packages\joblib\parallel.py", line 909, in retrieve
self._output.extend(job.get(timeout=self.timeout))
File "C:\ProgramData\Anaconda3\envs\deeplearning\lib\site-packages\joblib\_parallel_backends.py", line 562, in wrap_future_result
return future.result(timeout=timeout)
File "C:\ProgramData\Anaconda3\envs\deeplearning\lib\concurrent\futures\_base.py", line 435, in result
return self.__get_result()
File "C:\ProgramData\Anaconda3\envs\deeplearning\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
ValueError: The model is not configured to compute accuracy. You should pass `metrics=["accuracy"]` to the `model.compile()` method.
''''
I also tried this: '
try:
accuracies = cross_val_score(estimator = classifier, X = x_train, y = y_train, cv=10, n_jobs=-1, verbose=0)
except ValueError as e:
print ("ValueError:", e)
ValueError: The model is not configured to compute accuracy. You should pass `metrics=["accuracy"]` to the `model.compile()` method.
'
Upvotes: 1
Views: 322
Reputation: 56347
In your imports you are mixing imports between the keras
and tf.keras
packages, that is actually not supported, you should choose one and make all imports from the selected package.
Upvotes: 1