当前位置: 首页 > 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 中心化

相关文章:

  • 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 使用详解
  • 链接网站怎么做/企业网站有哪些平台
  • 做网站郑州汉狮/国内重大新闻10条
  • 最新手机资讯/广州网站优化方式
  • 日本插画网站/学大教育培训机构怎么样
  • 腾脉网建站/seo网络营销推广公司深圳
  • 苏州网站建设公司书生商友/国内seo公司排名