当前位置: 首页 > news >正文

【读代码】关于日期的处理

return np.vstack([feat(dates) for feat in time_features_from_frequency_str(freq)])

很多的类,用字典,调用类,还有类的重命名

除以 23 表示第几个小时,一天中的第几个小时

dayofhour是读出来的

dayofweek 是 python 内置库转换来

dayofmonth 也是可以直接读出来的

dayof year 也是直接读出来

为什么都减去 0.5:中心化

 奥,所以除以的数都比正常的小 1

规律:

为什么这里除以  11

class MonthOfYear(TimeFeature):

"""Month of year encoded as value between [-0.5, 0.5]"""

def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:

return (index.month - 1) / 11.0 - 0.5

这里的对于日期的编码还蛮有趣

class DayOfWeek(TimeFeature):
    """Hour of day encoded as value between [-0.5, 0.5]"""

    def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
        return index.dayofweek / 6.0 - 0.5 # Python内部返回 0——6 python内部计算 day 是周几,同时 除以 6 是为了把 周一到周六调成 0——1的范围,周一默认 0,周二=1,周日=6 so__都可以调到 0——1的范围内


class DayOfMonth(TimeFeature):
    """Day of month encoded as value between [-0.5, 0.5]"""

    def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
        return (index.day - 1) / 30.0 - 0.5 # 1——31


class DayOfYear(TimeFeature):
    """Day of year encoded as value between [-0.5, 0.5]"""

    def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
        return (index.dayofyear - 1) / 365.0 - 0.5 # 1——366


class MonthOfYear(TimeFeature):
    """Month of year encoded as value between [-0.5, 0.5]"""

    def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
        return (index.month - 1) / 11.0 - 0.5 # 1——12


class WeekOfYear(TimeFeature):
    """Week of year encoded as value between [-0.5, 0.5]"""

    def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
        return (index.isocalendar().week - 1) / 52.0 - 0.5 # 返回 1——53,--》-1 到 0——52 》-0.5 中心化

http://www.dtcms.com/a/49166.html

相关文章:

  • Full GC 排查
  • 网络安全法与等级保护 PPT 精华汇总
  • 探秘基带算法:从原理到5G时代的通信变革【五】CORDIC算法
  • 对于单片机检测直流信号的常用电路学习
  • SpringBoot整合Undertow提升性能的实战解析
  • LeetCode 25 - K 个一组翻转链表
  • safetensors PyTorchModelHubMixin 加载模型
  • 网络安全六层模型
  • USB2.0学习(1)
  • Unity+Vuforia 项目开发中的问题
  • Pytorch实现之SRGAN+CBAM的结构设计
  • 【Java反序列化测试】
  • C++初阶——入门基础1
  • 探秘基带算法:从原理到5G时代的通信变革【二】Viterbi解码
  • 关于C/C++的输入和输出
  • MySQL 8 C++ 源码解析:EXPLAIN 实现机制
  • 【嵌入式】MQTT
  • 深入探索DeepSeek开源之旅:开源Week全程解析
  • RHCE9.0版本笔记3:创建、查看和编辑文本文件
  • Qt QMenu 使用详解
  • AI+ERP:智能时代的双刃剑,从技术狂欢到价值落地的长征-亿发
  • 【前端场景题】如何应对页面请求接口的大规模并发问题
  • 【AI深度学习基础】Pandas完全指南入门篇:数据处理的瑞士军刀 (含完整代码)
  • 一个大型应用的云原生一般有多少个服务?
  • QT study DAY2
  • 【Qt QML】定时器(Timer)
  • DeepSeek搭配Excel,制作自定义按钮,实现办公自动化!
  • 下载b站视频音频
  • Linux 的at定时任务
  • 【Python 数据结构 2.时间复杂度和空间复杂度】