LLMTime 学习笔记, 时间序列数据处理的文本任务预测

个人点评 对我没起作用,没怎么理解透彻,没法用起来

LLMTime 简介

这个项目干啥的 就是把 时间序列数据 处理映射,成大模型易于理解的 提示词,然后利用大模型 通过API 调用返回 得到预测. 属于提示词工程.

项目地址:github_llmtime

一种基于大语言模型(LLM)的时间序列预测新方法LLMTIME。该方法将时间序列数据编码为数字字符串,然后将时间序列预测视为文本中的下一个标记预测问题。作者指出,这种方法可以利用预训练语言模型强大的概率建模能力和自然语言处理能力,实现对时间序列数据的有效建模和预测。具体来说,该方法首先对时间序列数据进行特殊的标记化处理,然后将标记序列输入到预训练的语言模型中,通过模型生成可能的预测标记序列。最后,根据生成标记序列的统计特征(如中值或分位数),可以得到时间序列的点预测或概率预测。通过在多个真实和合成时间序列数据集上进行评估,作者表明LLMTIME可以实现与专门训练的时间序列模型相比拟或更好的预测性能,而无需任何下游任务的微调。此外,作者还分析了LLMTIME的预测性能与基础语言模型的规模、结构化缺失数据处理以及模型对时间序列数据的多模态表达等方面的关系。总体而言,该论文为基于LLM的时间序列预测提供了一个简单有效的框架,并揭示了语言模型在时间序列预测中的潜在能力。



对于数据处理细节创新:

1.缺失值处理:

例如,对于一个包含缺失值的时间序列 [64,,, 49,, 16,] ,可以转换为 "64, NaN, NaN, 49, NaN, 16, NaN" 这样的文本表示.

2.灵活的概率密度估计:

举例来说,假设我们有一段模拟的时间序列数据,代表某个城市一年内每日的平均气温(摄氏度),如下所示:

[10.2, 11.5, 13.1, 15.3, 17.6, ..., 24.3, NaN, 22.7, 20.5, 16.8]

其中,“NaN”代表某一天的气温数据缺失。

在将这个时间序列转化为大型语言模型可以处理的文本形式时,我们可以将其编码为:

"10.2, 11.5, 13.1, 15.3, 17.6, ..., 24.3, NaN, 22.7, 20.5, 16.8"

接下来,为了将离散的令牌分布转化为连续值上的概率密度估计,我们需要模型不仅仅预测下一个可能出现的数字(如下一个气温值),还要对连续的气温变化区间有个概率分布的理解。为此,研究者可能采取的方法是将连续的气温区间划分为多个小的细分区间,例如:

  • [-∞, 10] 区间内的气温概率密度
  • [10, 15] 区间内的气温概率密度
  • [15, 20] 区间内的气温概率密度
  • [20, 25] 区间内的气温概率密度
  • [25, +∞] 区间内的气温概率密度

当模型处理上述文本形式的时间序列时,它会在每个细分区间内部学习一个概率分布,并基于已知数据(包括历史气温和缺失值的表示)推测未来的气温值落在各个区间的概率。这样,即使模型本身并未直接学到连续值的精确预测,也能通过这种方式间接生成连续的概率分布,进而对未知的气温值进行较为准确的估计。这有助于模型更好地拟合时间序列中的连续变化模式,例如四季更迭带来的气温起伏。

 

继续举例说明灵活的概率密度估计:

假设我们正在处理一个销售数据的时间序列,其中包括每个月的销售额(单位:万元)。原始数据序列如下:

[120.5, 152.3, 178.9, 195.1, 220.0, NaN, 245.6, 210.8, 180.2, 165.5]

同样,这里的“NaN”代表某个月份的销售额缺失。

为了转化成适合大型语言模型处理的文本格式,我们将每个数值用逗号分隔并去掉小数点后的多余数字,确保每个数字作为一个单独的令牌,同时保留缺失值的表示:

"120 5, 152 3, 178 9, 195 1, 220 0, NaN, 245 6, 210 8, 180 2, 165 5"

随后,为了将模型预测的离散数字转化为连续的销售额分布,我们将销售额范围细分为多个小区间(例如每个区间跨度为5万元),并对每个区间赋予一个均匀分布的概率密度。这样,当我们要求模型对未来一个月的销售额进行预测时,模型将不再只输出一个确切的数值,而是输出在各个区间内发生的可能性,如:

  • [150, 200] 区间内销售额的概率密度
  • [200, 250] 区间内销售额的概率密度
  • [250, 300] 区间内销售额的概率密度
  • ...以此类推

通过这种方式,模型能够灵活地估计连续变量(销售额)的分布状态,而不是仅仅预测单一的固定值,这有助于更准确地反映实际商业环境中的不确定性和动态变化。同时,这也意味着模型可以在处理时间序列时,更好地捕捉到销售额随时间逐渐上升、下降或是波动等连续变化模式。

3.日期映射方法 数据归一化

在时间特征编码时,无论是分钟、小时、天数还是月份,它们都被映射到了[-0.5, 0.5]的范围内。

年份一般不进行特殊转换。如果有相关的需求,开发者可以根据需要自行添加对年份特征的处理逻辑。

在时间特征编码时,将原始值减去1并除以周期总数的上限,然后减去0.5,这一做法主要是为了将时间特征映射到一个中心化的数值范围[-0.5, 0.5]内,:

映射公式:  导致的结果会落在区间的负半边 [0 - 0.5, -0.5] 内。
 (原始值 - 1) / 上限 - 0.5 
 为啥要减去1的原因

这里的“原始值减去1”是因为 转换成代码数组转换为从0开始的索引。
日期时间索引的day、month等属性是从1开始计数的,而不是从0开始。为了将这些属性映射到一个标准的区间(如[-0.5, 0.5]),
在Python的pandas库中,代码中我们需要将它们的值转换为从0开始的索引。因此,通过减去1,我们可以将原来从1开始的天数、月份等转换为从0开始的索引,然后再进行后续的标准化处理,确保所有数值都能落在期望的区间内,便于后续的数据分析和机器学习模型处理。

对于天数(DayOfMonth 或 DayOfYear 类),其映射方法是将天数减去1,然后除以一个月或一年中天数的一个合理估计值(例如,30天代表一个月的平均天数,365天代表一年的天数),最后减去0.5。这样做的目的是为了将原本不均匀分布的天数统一映射到一个固定区间,使得机器学习模型可以更容易地处理这些时间特征。例如:

从这些转换后的值中,我们可以观察到以下规律:

  1. 中心对称性:数值以0为中心对称。例如,1号的转换值是-0.5,而31号的转换值是0.5,它们在0的两侧,但绝对值相同。

  2. 线性增长:随着天数的增加,转换值线性增加。例如,从1号到2号,转换值从-0.5增加到-0.4677,增长量是正的,而且每天的增长量是相同的。

  3. 周期性:由于转换公式的设计,这些值在达到0.5后又从-0.5开始,形成了一个周期性的模式。这是因为在每个月的开始(1号),转换值被设置为-0.5,然后在每个月的最后一天(31号或30号或28/29号,取决于月份和是否是闰年),转换值达到0.5。

时间特征编码类的转化公式
  1. 小时(HourOfDay)

    • 公式小时值 / 23.0 - 0.5
    • 说明:将一天中的小时(0到23)编码为[-0.5, 0.5]范围内的值。其中,0时被编码为-0.5,而23时被编码为0.5。
  2. 星期(DayOfWeek)

    • 公式星期值 / 6.0 - 0.5
    • 说明:将星期中的天(0到6,通常对应星期一至星期日)编码为[-0.5, 0.5]范围内的值。星期一被编码为-0.5,而星期日被编码为0.5。
  3. 月份(DayOfMonth)

    • 公式(天数 - 1) / 30.0 - 0.5
    • 说明:将一个月中的天(1到31)编码为[-0.5, 0.5]范围内的值。1号被编码为-0.5,而31号(或该月最后一天)被编码为0.5。
  4. 天数(DayOfYear)

    • 公式(年度中的天 - 1) / 365.0 - 0.5
    • 说明:将一年中的天(1到366,考虑闰年)编码为[-0.5, 0.5]范围内的值。1月1日被编码为-0.5,而12月31日(或该年最后一天)被编码为0.5。
  5. 月份(MonthOfYear)

    • 公式(月份 - 1) / 11.0 - 0.5
    • 说明:将一年中的月份(1到12)编码为[-0.5, 0.5]范围内的值。1月被编码为-0.5,而12月被编码为0.5。
  6. (WeekOfYear)

    • 公式(年度中的周 - 1) / 52.0 - 0.5
    • 说明:将一年中的周(1到53)编码为[-0.5, 0.5]范围内的值。年度的第一个周被编码为-0.5,而最后一个周被编码为0.5。

class SecondOfMinute(TimeFeature):
    """Minute of hour encoded as value between [-0.5, 0.5]"""

    def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
        return index.second / 59.0 - 0.5


class MinuteOfHour(TimeFeature):
    """Minute of hour encoded as value between [-0.5, 0.5]"""

    def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
        return index.minute / 59.0 - 0.5


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

    def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
        return index.hour / 23.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


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


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


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 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

这个转换方法确保了时间特征在数值上具有周期性和连续性,这对于某些类型的机器学习模型(如循环神经网络RNN)是有益的,因为它们可以更好地捕捉时间序列数据中的周期性模式。

举例说明,将日期"2023-02-05"映射为数值特征的转换方法、原因和逻辑如下

    • 月份映射df_stamp['month'] = df_stamp.date.apply(lambda row: row.month, 1) 对于"2023-02-05",月份是2。标准化过程是将2除以一年中最大的月份数12,然后减去0.5,使得所有月份值位于[-0.5, 0.5]之间。所以标准化后的月份值为 (2 - 1) / 12 - 0.5 ≈ -0.4167

    • 日期映射df_stamp['day'] = df_stamp.date.apply(lambda row: row.day, 1) 对于"2023-02-05",日期是5。标准化过程是将5减去1(因为是从第1天开始计数),然后除以平均每月天数30,最后减去0.5。标准化后的日期值为 (5 - 1) / 30 - 0.5 ≈ -0.1333

数值转换

        将时间序列的数值转换为文本表示,使用逗号分隔不同的时间点,并在数字之间加入空格,以保持数值的完整性。
举例说明
数值转换是指将时间序列的数值转换为文本表示,以适应语言模型。举例说明:
假设原始时间序列数据为 [150, 165, 160, 155, 170, 175]。
按照LLMTIME方法,将这些数值转换为文本表示,可以在数字之间加入空格,并使用逗号分隔不同的时间点:
“1 5 0, 1 6 5, 1 6 0, 1 5 5, 1 7 0, 1 7 5”
这种转换方式保留了每个数字的原始信息,同时在数字之间加入了空格,避免了将数字分割成不完整的部分。这样的文本表示可以更好地适应语言模型的文本处理能力,从而实现对时间序列的建模和预测。

常见的标记化方法(如BPE)往往会将一个数字分解成与数字位数不对齐的标记,这可能会使得算术变得更加困难。例如,数字42235630在GPT-3标记器中可能被分解为[422, 35, 630]。
为了改进GPT模型的标记化问题,作者将数字之间用空格分开,以迫使每个数字单独进行标记化,并使用逗号来分隔时间序列中的每个时间步。由于给定固定精度后小数点是多余的,所以在编码时会丢弃它们以节省上下文长度。

对于GPT3来说,给数的每位之间加上空格(这样会把每位当成一个token),效果要比不加空格要好。

对于LLaMA来说,它本身的tokenizer就已经会把每位数当成一个token,因此无需再加空格,加了反而损害性能。

缩放

        对时间序列进行缩放,以避免过大或过小的数值导致预训练语言模型处理困难。通过缩放,可以让模型更好地处理时间序列数据。
例说明如下:
假设原始时间序列数据为 [1000, 2000, 3000, 4000, 5000]。
为了缩放数据,可以选择一个百分位数(如90%)作为缩放阈值,计算这个百分位数对应的数据值,然后使用这个值对数据进行缩放。具体步骤如下:
计算原始数据的90%百分位数,得到一个数值,例如3000。
使用这个数值作为缩放因子,对原始数据进行缩放:数据点 / 3000。
缩放后的时间序列数据为:[0.33, 0.67, 1, 1.33, 1.67]。
通过缩放,将原始数据转换到一个较小的范围内,有利于预训练语言模型更好地学习时间序列数据中的规律。这种缩放方法可以保留原始数据的信息,同时使模型更易处理。

对于-0.536  编码后


根据文档中的描述,对数字-0.536进行编码,处理步骤如下:
将小数点去掉,因为小数点对于数值的表示是冗余的,只保留整数部分和小数部分。
在每个数字之间添加空格,以将每个数字视为单独的标记。
使用逗号分隔每个数字,以保持数字的顺序。
对于负数,可以保留负号。
因此,-0.536编码后的表示为:" - 5 3 6 "。这样处理后的数字更适合语言模型的输入。 

'2023-02-12'

day_of_week: 6 -> 0.5 -> 500
day_of_month: 12 -> -0.133 -> -133
day_of_year: 43 -> -0.385 -> -385
month: 2 -> -0.409 -> -409
week_of_year: 7 -> -0.385 -> -385


一个月之天数转换

2023-01-01
day_of_week: 6 -> 0.5 -> 500
day_of_month: 1 -> -0.5 -> -500
day_of_year: 1 -> -0.5 -> -500
month_of_year: 1 -> -0.5 -> -500
week_of_year: 1 -> -0.5 -> -500
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-500,-500,-500 	
2023-01-02
day_of_week: 0 -> -0.5 -> -500
day_of_month: 2 -> -0.467 -> -467
day_of_year: 2 -> -0.497 -> -497
month_of_year: 1 -> -0.5 -> -500
week_of_year: 1 -> -0.5 -> -500
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-497,-500,-467 	
2023-01-03
day_of_week: 1 -> -0.333 -> -333
day_of_month: 3 -> -0.433 -> -433
day_of_year: 3 -> -0.495 -> -495
month_of_year: 1 -> -0.5 -> -500
week_of_year: 1 -> -0.5 -> -500
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-495,-500,-433 	
2023-01-04
day_of_week: 2 -> -0.167 -> -167
day_of_month: 4 -> -0.4 -> -400
day_of_year: 4 -> -0.492 -> -492
month_of_year: 1 -> -0.5 -> -500
week_of_year: 1 -> -0.5 -> -500
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-492,-500,-400 	
2023-01-05
day_of_week: 3 -> 0.0 -> 0
day_of_month: 5 -> -0.367 -> -367
day_of_year: 5 -> -0.489 -> -489
month_of_year: 1 -> -0.5 -> -500
week_of_year: 1 -> -0.5 -> -500
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-489,-500,-367 	
2023-01-06
day_of_week: 4 -> 0.167 -> 167
day_of_month: 6 -> -0.333 -> -333
day_of_year: 6 -> -0.486 -> -486
month_of_year: 1 -> -0.5 -> -500
week_of_year: 1 -> -0.5 -> -500
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-486,-500,-333 	
2023-01-07
day_of_week: 5 -> 0.333 -> 333
day_of_month: 7 -> -0.3 -> -300
day_of_year: 7 -> -0.484 -> -484
month_of_year: 1 -> -0.5 -> -500
week_of_year: 1 -> -0.5 -> -500
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-484,-500,-300 	
2023-01-08
day_of_week: 6 -> 0.5 -> 500
day_of_month: 8 -> -0.267 -> -267
day_of_year: 8 -> -0.481 -> -481
month_of_year: 1 -> -0.5 -> -500
week_of_year: 2 -> -0.481 -> -481
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-481,-500,-267 	
2023-01-09
day_of_week: 0 -> -0.5 -> -500
day_of_month: 9 -> -0.233 -> -233
day_of_year: 9 -> -0.478 -> -478
month_of_year: 1 -> -0.5 -> -500
week_of_year: 2 -> -0.481 -> -481
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-478,-500,-233 	
2023-01-10
day_of_week: 1 -> -0.333 -> -333
day_of_month: 10 -> -0.2 -> -200
day_of_year: 10 -> -0.475 -> -475
month_of_year: 1 -> -0.5 -> -500
week_of_year: 2 -> -0.481 -> -481
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-475,-500,-200 	
2023-01-11
day_of_week: 2 -> -0.167 -> -167
day_of_month: 11 -> -0.167 -> -167
day_of_year: 11 -> -0.473 -> -473
month_of_year: 1 -> -0.5 -> -500
week_of_year: 2 -> -0.481 -> -481
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-473,-500,-167 	
2023-01-12
day_of_week: 3 -> 0.0 -> 0
day_of_month: 12 -> -0.133 -> -133
day_of_year: 12 -> -0.47 -> -470
month_of_year: 1 -> -0.5 -> -500
week_of_year: 2 -> -0.481 -> -481
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-470,-500,-133 	
2023-01-13
day_of_week: 4 -> 0.167 -> 167
day_of_month: 13 -> -0.1 -> -100
day_of_year: 13 -> -0.467 -> -467
month_of_year: 1 -> -0.5 -> -500
week_of_year: 2 -> -0.481 -> -481
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-467,-500,-100 	
2023-01-14
day_of_week: 5 -> 0.333 -> 333
day_of_month: 14 -> -0.067 -> -67
day_of_year: 14 -> -0.464 -> -464
month_of_year: 1 -> -0.5 -> -500
week_of_year: 2 -> -0.481 -> -481
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-464,-500,-67 	
2023-01-15
day_of_week: 6 -> 0.5 -> 500
day_of_month: 15 -> -0.033 -> -33
day_of_year: 15 -> -0.462 -> -462
month_of_year: 1 -> -0.5 -> -500
week_of_year: 3 -> -0.462 -> -462
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-462,-500,-33 	
2023-01-16
day_of_week: 0 -> -0.5 -> -500
day_of_month: 16 -> 0.0 -> 0
day_of_year: 16 -> -0.459 -> -459
month_of_year: 1 -> -0.5 -> -500
week_of_year: 3 -> -0.462 -> -462
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-459,-500,0 	
2023-01-17
day_of_week: 1 -> -0.333 -> -333
day_of_month: 17 -> 0.033 -> 33
day_of_year: 17 -> -0.456 -> -456
month_of_year: 1 -> -0.5 -> -500
week_of_year: 3 -> -0.462 -> -462
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-456,-500,33 	
2023-01-18
day_of_week: 2 -> -0.167 -> -167
day_of_month: 18 -> 0.067 -> 67
day_of_year: 18 -> -0.453 -> -453
month_of_year: 1 -> -0.5 -> -500
week_of_year: 3 -> -0.462 -> -462
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-453,-500,67 	
2023-01-19
day_of_week: 3 -> 0.0 -> 0
day_of_month: 19 -> 0.1 -> 100
day_of_year: 19 -> -0.451 -> -451
month_of_year: 1 -> -0.5 -> -500
week_of_year: 3 -> -0.462 -> -462
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-451,-500,100 	
2023-01-20
day_of_week: 4 -> 0.167 -> 167
day_of_month: 20 -> 0.133 -> 133
day_of_year: 20 -> -0.448 -> -448
month_of_year: 1 -> -0.5 -> -500
week_of_year: 3 -> -0.462 -> -462
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-448,-500,133 	
2023-01-21
day_of_week: 5 -> 0.333 -> 333
day_of_month: 21 -> 0.167 -> 167
day_of_year: 21 -> -0.445 -> -445
month_of_year: 1 -> -0.5 -> -500
week_of_year: 3 -> -0.462 -> -462
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-445,-500,167 	
2023-01-22
day_of_week: 6 -> 0.5 -> 500
day_of_month: 22 -> 0.2 -> 200
day_of_year: 22 -> -0.442 -> -442
month_of_year: 1 -> -0.5 -> -500
week_of_year: 4 -> -0.442 -> -442
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-442,-500,200 	
2023-01-23
day_of_week: 0 -> -0.5 -> -500
day_of_month: 23 -> 0.233 -> 233
day_of_year: 23 -> -0.44 -> -440
month_of_year: 1 -> -0.5 -> -500
week_of_year: 4 -> -0.442 -> -442
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-440,-500,233 	
2023-01-24
day_of_week: 1 -> -0.333 -> -333
day_of_month: 24 -> 0.267 -> 267
day_of_year: 24 -> -0.437 -> -437
month_of_year: 1 -> -0.5 -> -500
week_of_year: 4 -> -0.442 -> -442
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-437,-500,267 	
2023-01-25
day_of_week: 2 -> -0.167 -> -167
day_of_month: 25 -> 0.3 -> 300
day_of_year: 25 -> -0.434 -> -434
month_of_year: 1 -> -0.5 -> -500
week_of_year: 4 -> -0.442 -> -442
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-434,-500,300 	
2023-01-26
day_of_week: 3 -> 0.0 -> 0
day_of_month: 26 -> 0.333 -> 333
day_of_year: 26 -> -0.432 -> -432
month_of_year: 1 -> -0.5 -> -500
week_of_year: 4 -> -0.442 -> -442
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-432,-500,333 	
2023-01-27
day_of_week: 4 -> 0.167 -> 167
day_of_month: 27 -> 0.367 -> 367
day_of_year: 27 -> -0.429 -> -429
month_of_year: 1 -> -0.5 -> -500
week_of_year: 4 -> -0.442 -> -442
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-429,-500,367 	
2023-01-28
day_of_week: 5 -> 0.333 -> 333
day_of_month: 28 -> 0.4 -> 400
day_of_year: 28 -> -0.426 -> -426
month_of_year: 1 -> -0.5 -> -500
week_of_year: 4 -> -0.442 -> -442
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-426,-500,400 	
2023-01-29
day_of_week: 6 -> 0.5 -> 500
day_of_month: 29 -> 0.433 -> 433
day_of_year: 29 -> -0.423 -> -423
month_of_year: 1 -> -0.5 -> -500
week_of_year: 5 -> -0.423 -> -423
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-423,-500,433 	
2023-01-30
day_of_week: 0 -> -0.5 -> -500
day_of_month: 30 -> 0.467 -> 467
day_of_year: 30 -> -0.421 -> -421
month_of_year: 1 -> -0.5 -> -500
week_of_year: 5 -> -0.423 -> -423
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-421,-500,467 	
2023-01-31
day_of_week: 1 -> -0.333 -> -333
day_of_month: 31 -> 0.5 -> 500
day_of_year: 31 -> -0.418 -> -418
month_of_year: 1 -> -0.5 -> -500
week_of_year: 5 -> -0.423 -> -423
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-418,-500,500 	
2023-02-01
day_of_week: 2 -> -0.167 -> -167
day_of_month: 1 -> -0.5 -> -500
day_of_year: 32 -> -0.415 -> -415
month_of_year: 2 -> -0.409 -> -409
week_of_year: 5 -> -0.423 -> -423
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-415,-409,-500 	
2023-02-02
day_of_week: 3 -> 0.0 -> 0
day_of_month: 2 -> -0.467 -> -467
day_of_year: 33 -> -0.412 -> -412
month_of_year: 2 -> -0.409 -> -409
week_of_year: 5 -> -0.423 -> -423
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-412,-409,-467 	
2023-02-03
day_of_week: 4 -> 0.167 -> 167
day_of_month: 3 -> -0.433 -> -433
day_of_year: 34 -> -0.41 -> -410
month_of_year: 2 -> -0.409 -> -409
week_of_year: 5 -> -0.423 -> -423
result:年,day_of_year_encoded,month_of_year_encoded,day_of_month_encoded
result: 2023,-410,-409,-433 	

2023-01-01
day_of_month: 1 -> -0.5 -> -500
2023-01-02
day_of_month: 2 -> -0.467 -> -467
2023-01-03
day_of_month: 3 -> -0.433 -> -433
2023-01-04
day_of_month: 4 -> -0.4 -> -400
2023-01-05
day_of_month: 5 -> -0.367 -> -367
2023-01-06
day_of_month: 6 -> -0.333 -> -333
2023-01-07
day_of_month: 7 -> -0.3 -> -300
2023-01-08
day_of_month: 8 -> -0.267 -> -267
2023-01-09
day_of_month: 9 -> -0.233 -> -233
2023-01-10
day_of_month: 10 -> -0.2 -> -200
2023-01-11
day_of_month: 11 -> -0.167 -> -167
2023-01-12
day_of_month: 12 -> -0.133 -> -133
2023-01-13
day_of_month: 13 -> -0.1 -> -100
2023-01-14
day_of_month: 14 -> -0.067 -> -67
2023-01-15
day_of_month: 15 -> -0.033 -> -33
2023-01-16
day_of_month: 16 -> 0.0 -> 0
2023-01-17
day_of_month: 17 -> 0.033 -> 33
2023-01-18
day_of_month: 18 -> 0.067 -> 67
2023-01-19
day_of_month: 19 -> 0.1 -> 100
2023-01-20
day_of_month: 20 -> 0.133 -> 133
2023-01-21
day_of_month: 21 -> 0.167 -> 167
2023-01-22
day_of_month: 22 -> 0.2 -> 200
2023-01-23
day_of_month: 23 -> 0.233 -> 233
2023-01-24
day_of_month: 24 -> 0.267 -> 267
2023-01-25
day_of_month: 25 -> 0.3 -> 300
2023-01-26
day_of_month: 26 -> 0.333 -> 333
2023-01-27
day_of_month: 27 -> 0.367 -> 367
2023-01-28
day_of_month: 28 -> 0.4 -> 400
2023-01-29
day_of_month: 29 -> 0.433 -> 433
2023-01-30
day_of_month: 30 -> 0.467 -> 467
2023-01-31
day_of_month: 31 -> 0.5 -> 500

  • 7
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于Python中的时间序列多步预测,可以使用长短期记忆网络(LSTM)来实现。LSTM是一种适用于处理序列数据的深度学习模型,它可以捕捉序列中的长期依赖关系。 在Python中,可以使用Keras库来构建和训练LSTM模型。首先,需要准备好时间序列数据,并将其转换为适合LSTM模型的输入格式。通常,可以将时间序列数据转换为监督学习问题,其中输入序列用于预测输出序列的下一个时间步。 接下来,可以使用Keras中的LSTM层来构建LSTM模型。可以指定LSTM层的神经元数量、输入序列长度和输出序列长度等参数。然后,可以将LSTM层与其他层(如全连接层)组合起来构建完整的模型。 在训练模型之前,需要将数据集划分为训练集和测试集。可以使用训练集来训练模型,并使用测试集来评估模型的性能。 在训练过程中,可以使用适当的损失函数和优化算法来最小化模型预测误差。可以使用均方误差(MSE)作为损失函数,并使用随机梯度下降(SGD)或Adam优化算法来优化模型。 最后,可以使用训练好的模型来进行多步预测。可以将模型输入最后几个时间步的数据,然后使用模型预测未来多个时间步的值。 如果你想了解更多关于Python中使用LSTM进行时间序列多步预测的详细信息,可以参考\[1\]中提供的链接和\[2\]中提供的GitHub源码地址。这些资源将提供更具体的实现细节和示例代码。 #### 引用[.reference_title] - *1* *2* [Python时间序列LSTM预测系列学习笔记(10)-多步预测](https://blog.csdn.net/yangwohenmai1/article/details/84568633)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值