Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'history' is not defined

Setting up the Model, Setting up Training and Validation Data for the experiment, Model Training has executed. But after training of the neural network, during Visualizing the Training Process, I received an error.

import matplotlib.pyplot as plt
%matplotlib inline

acc=history.history['categorical_accuracy']
val_acc=history.history['val_categorical_accuracy']
loss=history.history['loss']
val_loss=history.history['val_loss']

epochs=range(1,len(acc)+1)
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.plot(epochs, acc, 'bo', label='Training acc')
plt.plot(epochs, val_acc, 'b', label='Validation acc')
plt.title('Training and validation accuracy')
plt.legend()
plt.figure()

plt.plot(epochs, loss, 'bo', label='Training loss')
plt.plot(epochs, val_loss, 'b', label='Validation loss')
plt.title('Training and validation loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()
NameError                                 Traceback (most recent call last)
<ipython-input-7-e1591c31f061> in <module>()
      2 get_ipython().magic('matplotlib inline')
      3 
----> 4 acc=history.history['categorical_accuracy']
      5 val_acc=history.history['val_categorical_accuracy']
      6 loss=history.history['loss']

NameError: name 'history' is not defined
like image 658
Nazia Ashraf Avatar asked Nov 01 '25 14:11

Nazia Ashraf


1 Answers

When you call model.fit it should be

history = model.fit()
like image 67
Gerry P Avatar answered Nov 04 '25 04:11

Gerry P