愉快的学习就从翻译开始吧_Multivariate Time Series Forecasting with LSTMs in Keras_1_Air Pollution Forecasting

本教程使用北京美国大使馆五年的空气质量数据集,探讨如何根据历史天气和污染情况预测下一小时的PM2.5浓度。

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

1. Air Pollution Forecasting/空气污染预测

In this tutorial, we are going to use the Air Quality dataset.

本教程中我们将使用空气质量数据集

This is a dataset that reports on the weather and the level of pollution each hour for five years at the US embassy in Beijing, China.

这是一个数据集,报告了美国在中国北京的大使馆五年每小时的天气和污染水平

The data includes the date-time, the pollution called PM2.5 concentration, and the weather information including dew point, temperature, pressure, wind direction, wind speed and the cumulative number of hours of snow and rain. The complete feature list in the raw data is as follows:

这些数据包括时间,称为PM2.5浓度的污染,和包括露珠,温度,压力,风向,风速和雨雪累积时间的天气信息,原始数据中完整的特征如下所列:

  1. No: row number/行号
  2. year: year of data in this row/年
  3. month: month of data in this row/月
  4. day: day of data in this row/日
  5. hour: hour of data in this row/小时
  6. pm2.5: PM2.5 concentration/PM2.5
  7. DEWP: Dew Point/露
  8. TEMP: Temperature/温度
  9. PRES: Pressure/压力
  10. cbwd: Combined wind direction/组合风向(大概就像东北风,西南风之类的,哈哈)
  11. Iws: Cumulated wind speed/累计风速(计算平均值,还是怎么的?)
  12. Is: Cumulated hours of snow/积雪小时
  13. Ir: Cumulated hours of rain/集雨小时

We can use this data and frame a forecasting problem where, given the weather conditions and pollution for prior hours, we forecast the pollution at the next hour.

我们可以用这个数据,构建一个预测问题,给出前几小时的天气状况和污染(PM2.5),我们预测接下来几个小时的污染(PM2.5)

This dataset can be used to frame other forecasting problems.

这个数据集可以用来构建别的预测问题(估计意思是除了PM2.5之外的其他预测,如集雨,积雪小时等)

Do you have good ideas? Let me know in the comments below.

你有好主意吗?请在下面的评论中告诉我

You can download the dataset from the UCI Machine Learning Repository.

您可以从UCI Machine Learning Repository下载数据集。

Download the dataset and place it in your current working directory with the filename “raw.csv“.

下载数据集并将其放在当前工作目录中,文件名为“raw.csv”。

### HDMixer 方法概述 HDMixer 是一种基于分层依赖关系混合的方法,旨在通过扩展补丁技术来改进多变量时间序列预测的效果[^1]。该方法的核心在于利用层次化结构捕获不同尺度的时间依赖性,并通过可扩展的补丁机制增强模型对局部特征的学习能力。 #### 层次化依赖建模 HDMixer 的设计目标之一是有效捕捉时间序列数据中的多层次依赖关系。具体而言,它通过对输入时间序列进行逐级分解,在不同的抽象级别上提取特征。这种方法能够帮助模型更好地理解短期波动与长期趋势之间的关联。 #### 可扩展补丁机制 为了进一步提升性能,HDMixer 引入了一种称为 **Extendable Patch** 的创新组件。这一机制允许模型动态调整其感受野大小,从而适应不同类型的数据分布特性。相比传统的固定窗口策略,这种灵活性显著提高了模型对于复杂模式识别的能力。 以下是实现 HDMixer 的基本框架: ```python import torch import torch.nn as nn class HDMixer(nn.Module): def __init__(self, input_dim, hidden_dim, num_layers=3, patch_size=8): super(HDMixer, self).__init__() layers = [] for _ in range(num_layers): layers.append( nn.Sequential( nn.Linear(input_dim * patch_size, hidden_dim), nn.GELU(), nn.Linear(hidden_dim, input_dim) ) ) self.mixer_blocks = nn.ModuleList(layers) def forward(self, x): # 输入形状 (batch_size, seq_len, input_dim) patches = x.unfold(dimension=-2, size=self.patch_size, step=self.patch_size).squeeze(-1) # 切片成补丁 for block in self.mixer_blocks: out = block(patches.flatten(start_dim=-2)) # 补丁展平并送入Mixer Block patches += out.view(*patches.shape) # 残差连接 return patches.mean(dim=-2) # 对所有补丁取平均作为最终输出 model = HDMixer(input_dim=10, hidden_dim=64, num_layers=3, patch_size=8) input_data = torch.randn(32, 100, 10) # 假设批量大小为32,序列长度为100,维度为10 output = model(input_data) print(output.shape) # 输出应为(batch_size, input_dim),即(32, 10) ``` 上述代码展示了如何构建一个简单的 HDMixer 架构。其中 `unfold` 函数被用来创建滑动窗口形式的补丁;而多个线性变换则共同组成了核心的混频操作。 ### 多变量时间序列预测中的应用 在实际应用场景下,HDMixer 能够很好地处理具有高维性和强噪声特性的多变量时间序列数据集。例如,在电力负荷预测、金融市场分析等领域均展现出优越的表现。相比于其他先进算法如 TSMixer 和 MSGNet ,它的优势体现在以下几个方面: - 更高效的计算资源利用率; - 更强大的跨尺度交互表达力; - 面向非平稳过程优化的设计理念[^3]。 值得注意的是,虽然 Transformers 类模型近年来成为主流选择,但由于其固有的内存消耗问题,在面对极长历史记录时仍存在局限性[^4]。因此像 HDMixer 这样专注于简化架构同时保持竞争力的技术显得尤为重要。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值