我试图在keras中绘制训练图,但是在运行代码时发生错误。
def modelx(X, y):
classifier = Sequential()
classifier.add(Dense(4, activation='relu', kernel_initializer='random_normal', input_dim=10))
classifier.add(Dense(4, activation='relu', kernel_initializer='random_normal'))
classifier.add(Dense(1, activation='sigmoid', kernel_initializer='random_normal'))
classifier.compile(optimizer='adam', loss='binary_crossentropy', metrics =['accuracy'])
out = classifier.fit(X, y, batch_size=10, epochs=1000, verbose=0)
return out, classifier
..............
..............
..............
predictions, model = modelx(X, y)
predictions = model.predict(test)
predictions = (predictions>0.5)
predictions = predictions.astype(int)
print(predictions)
results = ids.assign(Survived=predictions)
results.to_csv("/home/navaneeth/work/kaggle/titanic/gender_submission.csv", index=False)
scores = model.evaluate(test, predictions, verbose=0)
print(scores)
print(predictions.history.keys())
plt.plot(predictions.history['acc'])
plt.plot(predictions.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
错误似乎
print(predictions.history.keys()) AttributeError:“ numpy.ndarray”对象没有属性“ history”
答案 0 :(得分:0)