我按照FrançoisChollet撰写的《使用Python进行深度学习》一书的指示进行操作,我想尝试IMDB数据集的示例。但是在google Collabs上编写代码后,我得到了一些奇怪的图形:
Training and validation loss graphic
Training and validation accuracy graphic
这本书的图形:
Validation loss and validation accuracy graphics
这本书的代码和我写的代码之间的区别在这里:
图书代码:
> df[,11:14]
rating combined1 combined2 combined3
1 1 1, a, #ji 1, 190 1890, NA
2 2 0, b, #ki 2, 2345 9002, @ksdf
3 3 1, c, NA 3, 41 14341, NA
4 4 4, d, #ui 4, 89 657, NA
有关验证准确性的图书代码:
import matplotlib.pyplot as plt
history_dict = history.history
loss_values = history_dict['loss']
val_loss_values = history_dict['val_loss']
epochs = range(1, len(acc) + 1)
plt.plot(epochs, loss_values, 'bo', label='Training loss')
plt.plot(epochs,val_loss_values,'b',label='Validationloss')
plt.title('Training and validation loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()
我的代码:
plt.clf()
acc_values = history_dict['acc']
val_acc_values = history_dict['val_acc']
plt.plot(epochs, acc, 'bo', label='Training acc')
plt.plot(epochs, val_acc, 'b', label='Validation acc')
plt.title('Training and validation accuracy')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()
为了验证准确性:
import matplotlib.pyplot as plt
history_dict = history.history
loss_values = history_dict['loss']
val_loss_values = history_dict['val_loss']
acc_values = history_dict['acc']
val_acc_values = history_dict['val_acc']
epochs = range(1, len(acc_values) + 1)
plt.plot(epochs, loss_values, 'bo', label = 'Trainingloss')
plt.plot(epochs,val_loss_values,'b',label='Validationloss')
plt.title ('Training and validation loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()
我更改代码的原因是因为当我编写原始代码时,出现以下错误:
plt.clf()
plt.plot(epochs, val_acc_values, 'bo', label='Training acc')
plt.plot(epochs, acc_values, 'b', label='Validation acc')
plt.title('Training and validation accuracy')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()
对我来说,我需要参加的认证是对象历史的认证,这说明了我所做的修改,并且由于我刚开始学习深度学习,所以不确定我是否做对了。
在这里,您已经在Google Collabs中制作了我的完整程序:
NameError Traceback (most recent call last)
<ipython-input-21-90f572222de2> in <module>()
3 loss_values = history_dict['loss']
4 val_loss_values = history_dict['val_loss']
----> 5 epochs = range(1, len(acc) + 1)
6 plt.plot(epochs, loss_values, 'bo', label='Training loss')
7 plt.plot(epochs, val_loss_values, 'b', label='Validation loss')
NameError: name 'acc' is not defined