msba
msba

Reputation: 139

Evaluation of keras model returns loss:0 and accuracy:0

I am trying to learn keras. As tutorial I used this https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/ Why does model.evaluate(X) returns loss:0 and accuracy:0?

# first neural network with keras make predictions
from numpy import loadtxt
from keras.models import Sequential
from keras.layers import Dense
# load the dataset
dataset = loadtxt('pima-indians-diabetes.csv', delimiter=',')
# split into input (X) and output (y) variables
X = dataset[:,0:8]
y = dataset[:,8]
# define the keras model
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# compile the keras model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# fit the keras model on the dataset
model.fit(X, y, epochs=150, batch_size=10)
# make class predictions with the model
predictions = (model.predict(X) > 0.5).astype(int)
# summarize the first 5 cases
for i in range(5):
    print('%s => %d (expected %d)' % (X[i].tolist(), predictions[i], y[i]))

print(model.evaluate(X))
print(model.predict(X[-5:]))

Terminal: enter image description here

Upvotes: 1

Views: 1150

Answers (1)

msba
msba

Reputation: 139

I forgot to add the target output to the model.evaluate().

print(model.evaluate(X, y))

This works fine!

Upvotes: 4

Related Questions