0
votes

i'm trying to plot the training diagram in keras but error occured while running the code.

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()

the error seems

print(predictions.history.keys()) AttributeError: 'numpy.ndarray' object has no attribute 'history'

1
Check this to know how to use .history(). - shaik moeed

1 Answers

0
votes

You should not use history on predictions, just on model which you previously train. So model.history.keys() in my opinion is exactly what you need to do.

You can find more information here:

Keras callbacks