[keras] 观察精度/mtlplotlib

本文介绍如何使用Matplotlib绘制图表,并通过Keras训练模型,展示训练过程中的损失与准确率变化。具体包括定义图像窗口、绘制训练与验证数据的损失及准确率曲线。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

matplotlib

plt.figure() 定义一个图像窗口 plt.figure(num=3, figsize=(8, 5),) 编号为3,大小为(8, 5)
plt.plot(x, y) plt.plot画(x ,y)曲线 , plt.plot(x, y1, color=‘red’, linewidth=1.0, linestyle=’–’)
plt.show() plt.show显示图像.

keras history object

# define the function
def training_vis(hist):
    loss =    hist.history['loss'] 
    val_loss = hist.history['val_loss']
    acc = hist.history['acc']
    val_acc = hist.history['val_acc']

    # make a figure
    fig = plt.figure(figsize=(8,4))
    # subplot loss
    ax1 = fig.add_subplot(121)
    ax1.plot(loss,label='train_loss')
    ax1.plot(val_loss,label='val_loss')
    ax1.set_xlabel('Epochs')
    ax1.set_ylabel('Loss')
    ax1.set_title('Loss on Training and Validation Data')
    ax1.legend()
    # subplot acc
    ax2 = fig.add_subplot(122)
    ax2.plot(acc,label='train_acc')
    ax2.plot(val_acc,label='val_acc')
    ax2.set_xlabel('Epochs')
    ax2.set_ylabel('Accuracy')
    ax2.set_title('Accuracy  on Training and Validation Data')
    ax2.legend()
    plt.tight_layout()
 hist = model.fit(...)

 training_vis(hist)

在这里插入图片描述

https://www.cnblogs.com/tectal/p/9426994.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值