【问题标题】:Evaluation of keras model returns loss:0 and accuracy:0keras 模型的评估返回损失:0 和准确度:0
【发布时间】:2022-01-16 22:55:12
【问题描述】:

我正在尝试学习 keras。作为教程,我使用了这个https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/ 为什么 model.evaluate(X) 返回 loss:0 和 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:]))

终端:

【问题讨论】:

    标签: python tensorflow keras evaluate


    【解决方案1】:

    我忘记将目标输出添加到 model.evaluate()。

    print(model.evaluate(X, y))
    

    这很好用!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-28
      • 2020-08-25
      • 2020-07-02
      • 2022-01-11
      • 1970-01-01
      • 2021-11-19
      • 2020-05-19
      • 1970-01-01
      相关资源
      最近更新 更多