无法去除趋势成分和季节性成分

我正在尝试使用ARMA模型来建立一个预测能源生产的模型。

我可以用于训练的数据如下所示;

https://github.com/soma11soma11/EnergyDataSimulationChallenge/blob/master/challenge1/data/training_dataset_500.csv

ID  Label   House   Year    Month   Temperature Daylight    EnergyProduction0     0       1     2011     7         26.2      178.9         7401     1       1     2011     8         25.8      169.7         7312     2       1     2011     9         22.8      170.2         6943     3       1     2011     10        16.4      169.1         6884     4       1     2011     11        11.4      169.1         6505     5       1     2011     12         4.2      199.5         763...............11995 19     500    2013     2          4.2      201.8         63811996 20     500    2013     3         11.2        234         77811997 21     500    2013     4         13.6      237.1         75811998 22     500    2013     5         19.2      258.4         83811999 23     500    2013     6         22.7      122.9         586

如上所示,我可以使用2011年7月至2013年5月的数据进行训练。通过这些训练数据,我希望预测2013年6月每500户的能源生产情况。

问题在于时间序列数据不是平稳的,并且具有趋势成分和季节性成分(我通过以下方式进行了检查)。

import csvimport numpy as npimport pandas as pdimport matplotlib.pyplot as pltdata_train = pd.read_csv('../../data/training_dataset_500.csv')rng=pd.date_range('7/1/2011', '6/1/2013', freq='M')house1 = data_train[data_train.House==1][['EnergyProduction','Daylight','Temperature']].set_index(rng)fig, axes = plt.subplots(nrows=1, ncols=3)for i, column in enumerate(house1.columns):    house1[column].plot(ax=axes[i], figsize=(14,3), title=column)plt.show()

enter image description here

使用这些数据,我无法通过ARMA模型获得良好的预测结果。因此,我希望去除趋势成分和季节性成分,使时间序列数据变得平稳。我尝试解决这个问题,但无法去除这些成分并使其平稳。


回答:

我建议使用Hodrick-Prescott(HP)滤波器,这在宏观计量经济学中被广泛用于将长期趋势成分与短期波动分离。它在statsmodels.api.tsa.filters.hpfilter中实现。

import pandas as pdimport matplotlib.pyplot as pltimport statsmodels.api as smdf = pd.read_csv('/home/Jian/Downloads/data.csv', index_col=[0])# 获取部分数据x = df.loc[df.House==1, 'Daylight']# hp-filter,根据月度数据的建议设置参数lamb=129600x_smoothed, x_trend = sm.tsa.filters.hpfilter(x, lamb=129600)fig, axes = plt.subplots(figsize=(12,4), ncols=3)axes[0].plot(x)axes[0].set_title('原始数据')axes[1].plot(x_trend)axes[1].set_title('趋势')axes[2].plot(x_smoothed)axes[2].set_title('平滑数据')

enter image description here

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注