【快速实践】深度学习 -- 数据曲线平滑化

希望对你有帮助呀!!💜💜 如有更好理解的思路,欢迎大家留言补充 ~ 一起加油叭 💦
欢迎关注、订阅专栏 【深度学习从 0 到 1】谢谢你的支持!


在观察数据结果时,我们通常希望获得整体趋势信息 – 所以可以应用平滑化手段绘制更易读的曲线

  • 以数据 d = np.random.random(20) 为例:
    import numpy as np
    import matplotlib.pyplot as plt
    
    d = np.random.random(20)
    
    # 平滑化函数 -- 指数移动平均值:
    # smooth_point = previous * factor + point * (1 - factor)
    def smooth_curve(points, factor=0.8): 
        smoothed_points = [] 
        for point in points: 
            if smoothed_points: 
                previous = smoothed_points[-1] 
                smoothed_points.append(previous * factor + point * (1 - factor)) 
            else: 
                smoothed_points.append(point) 
        return smoothed_points 
    
    plt.figure()
    xdata = list(range(len(d)))
    
    # 绘制平滑前和后曲线
    plt.plot(xdata, d, color='yellow', label="Smoothed (Before)")  # 平滑前,黄色
    plt.plot(xdata, smooth_curve(d), color='orange', label="Smoothed (After)")  # 平滑后,橙色
    
    # 填充两个曲线之间的区域,透明黄色
    plt.fill_between(xdata, d, smooth_curve(d), color='yellow', alpha=0.3)
    
    plt.xlabel("episode")
    plt.ylabel("reward")
    plt.legend()
    
    plt.show()
    

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值