我用keras训练了一个模型
model.fit(train_array, labels, batch_size=32, epochs=10, validation_split=0.3)
返回了如下的loss和val_loss
Epoch 1/10
17500/17500 [==============================] - 2s 120us/step - loss: 0.6638 - val_loss: 0.6066
Epoch 2/10
17500/17500 [==============================] - 1s 62us/step - loss: 0.5379 - val_loss: 0.4775
Epoch 3/10
17500/17500 [==============================] - 1s 61us/step - loss: 0.4247 - val_loss: 0.3939
Epoch 4/10
17500/17500 [==============================] - 1s 63us/step - loss: 0.3525 - val_loss: 0.3480
Epoch 5/10
17500/17500 [==============================] - 1s 62us/step - loss: 0.3077 - val_loss: 0.3162
Epoch 6/10
17500/17500 [==============================] - 1s 61us/step - loss: 0.2783 - val_loss: 0.2991
Epoch 7/10
17500/17500 [==============================] - 1s 61us/step - loss: 0.2573 - val_loss: 0.2878
Epoch 8/10
17500/17500 [==============================] - 1s 60us/step - loss: 0.2418 - val_loss: 0.2815
Epoch 9/10
17500/17500 [==============================] - 1s 63us/step - loss: 0.2299 - val_loss: 0.2779
Epoch 10/10
17500/17500 [==============================] - 1s 62us/step - loss: 0.2203 - val_loss: 0.2750
我怎么根据这个loss和val_loss画图?就像底下这个图的效果
1个回答
你要把model.fit的训练过程保存下来
history = model.fit(...)
history是一个dict,dict里有history子dict,里面有loss和val_loss,都是list的形式,然后就可以正常画图了
epochs = len(history.history['loss'])
plt.plot(range(epochs), history.history['loss'], label='loss')
plt.plot(range(epochs), history.history['val_loss'], label='val_loss')
plt.legend()
plt.show()
SofaSofa数据科学社区DS面试题库 DS面经
很有帮助,谢谢!
-
xkk1o
2019-07-27 14:20
相关讨论
Keras模型针对同一数据集做fit和evaluation,accuracy值却不相同
keras sequential model怎么增加一个dropout层?
keras加载imdb数据时num_words参数是干嘛的?
keras里的predict,predict_classes,predict_proba有什么区别?
keras无法加载imdb文本:Object arrays cannot be loaded when allow_pickle=False
随便看看
pandas.DataFrame里的loc和iloc什么区别?