MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

FateMurphy/CEEMDAN_LSTM 深度技术分析

项目背景与痛点

在时间序列分析领域,准确的预测一直是关键挑战。传统的预测模型往往会受到数据中的深层复杂结构影响,导致预测结果不准确。CEEMDAN_LSTM 项目旨在通过结合完全集成的 CEEMDAN (Complete Ensemble Empirical Mode Decomposition with Adaptive Noise) 和 LSTM (Long Short-Term Memory) 网络,对时间序列数据进行有效的分解与集成预测。其核心优势在于,CEEMDAN 方法能对数据进行自适应分解,从而捕捉不同尺度下的特征,而 LSTM 则擅长学习这些特征之间的长期依赖关系。这使得该项目能够应对复杂的时间序列数据,提供更加准确和可靠的预测结果。

核心技术揭秘

CEEMDAN_LSTM 项目的实现依赖于两个核心技术:CEEMDAN 和 LSTM 神经网络。首先,CEEMDAN 负责将原始时间序列数据分解为多个内在模式函数 (IMF),每个 IMF 对应数据中的某个特定频率分量。之后,LSTM 网络则针对这些 IMFs 进行联合建模,通过学习其内在模式,实现对整体时间序列数据的更准确预测。

以下是项目的核心架构图:

graph TD A[原始数据] --> B[CEEMDAN 分解] B --> C{"IMF 分解结果"} C -->|"各个 IMF" | D[LSTM 预测] D --> E[整体预测结果]

详细实现步骤

  1. 数据预处理:原始数据首先通过预处理步骤,如归一化,移除噪声等,以确保后续步骤的健壮性和准确性。
  2. CEEMDAN 分解:通过 CEEMDAN,原始数据被分解为一系列 IMFs 和一个残差。每个 IMF 表示数据中的一个固有频率分量,便于后续的建模操作。
  3. LSTM 建模:各个 IMF 被分别输入到 LSTM 网络中,通过学习 IMFs 之间的关系,LSTM 模型可以捕捉到数据中的长短期依赖关系。
  4. 集成预测:最终的预测结果通过各个 LSTM 模型的预测结果进行组合,获得最终的预测输出。

功能亮点与差异

与其他时间序列预测工具相比,CEEMDAN_LSTM 的独特之处在于其结合了 CEEMDAN 的分解特性和 LSTM 的建模能力。CEEMDAN 可以处理复杂的时间序列数据,并有效隔绝噪声。LSTM 则擅长提取长短期依赖关系,实现更加精准的预测。这使得 CEEMDAN_LSTM 在金融市场预测、天气预报等领域的表现尤其突出。

此外,项目中提供的预处理步骤和优化的参数选择,能够进一步提升模型的鲁棒性和泛化能力。这些设计细节使得 CEEMDAN_LSTM 成为一个开源社区中的有力工具,适用于多种复杂应用场景。

应用场景与落地建议

在实际生产环境使用 CEEMDAN_LSTM 时,有几个关键点需要注意:

  • 数据复杂度:CEEMDAN 分解对于数据复杂度较高的场景非常有效。因此,应选择具备复杂模式数据进行实验。
  • 计算资源:CEEMDAN 分解和 LSTM 建模过程都很耗时。优化模型配置和硬件资源是提高训练和预测速度的关键。
  • 数据预处理:不同时间序列数据的特征不同,因此需要针对性地调整预处理步骤,确保数据质量。

适用场景

  • 金融市场:股票价格、外汇走势、期货价格等高频时间序列数据的预测。
  • 气象预报:复杂天气数据的分析和预测。
  • 能源预测:电力需求预测、风力发电和光伏系统效率预测等。
  • 物联网数据分析:多种传感器数据的监测和预测。

综合评价

CEEMDAN_LSTM 项目在时间序列预测领域引入了极具优势的技术框架。它提供的 CEEMDAN 分解与 LSTM 结合的方式,可以高效处理复杂的时间序列数据。然而,用户在实际使用时,需要配置合适的硬件资源,并针对具体数据特征调整预处理步骤,以优化模型性能。

优点

  • 高效的数据分析和预测能力。
  • 适用于复杂时间序列数据的通用性和准确性。
  • 开源社区活跃,容易进行二次开发和实验。

缺点

  • 数据处理和模型训练较为耗时。
  • 对硬件资源要求较高。

总的来说,CEEMDAN_LSTM 是一个值得推荐的时间序列分析工具,适用于需要精准预测的各种复杂应用场景。

关于

GitHub 原始描述(英文)

CEEMDAN_LSTM is a Python project for decomposition-integration forecasting models based on EMD methods and LSTM.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
704
价值分
224
活跃状态
活跃

语言占比

Jupyter Notebook
Python

Release

贡献者

README

CEEMDAN_LSTM

GitHub: https://github.com/FateMurphy/CEEMDAN_LSTM
Future work: CFS

Background

CEEMDAN_LSTM is a Python module for decomposition-integration forecasting models based on EMD methods and LSTM. It aims at helping beginners quickly make a decomposition-integration forecasting by CEEMDAN, Complete Ensemble Empirical Mode Decomposition with Adaptive Noise (Torres et al. 2011), and LSTM, Long Short-Term Memory recurrent neural network (Hochreiter and Schmidhuber, 1997). If you use or refer to the content of this module, please cite the paper: (F. Zhou, Z. Huang, C. Zhang, Carbon price forecasting based on CEEMDAN and LSTM, Applied Energy, 2022, Volume 311, 118601, ISSN 0306-2619.).

Flowchart

Note, as it decomposes the entire series first, there is some look-ahead bias.

Install

The quickest way to install the package is through pip.

pip install CEEMDAN_LSTM

(2) From the package

Download the package CEEMDAN_LSTM-1.2.tar.gz by clicking Code -> Download ZIP. After unzipping, move the package where you like.

pip install .(your file path)/CEEMDAN_LSTM-1.2.tar.gz

(3) From source

If you want to modify the code, you should download the code and build the package yourself. The source is publically available and hosted on GitHub: https://github.com/FateMurphy/CEEMDAN_LSTM. To download the code, you can either go to the source code page and click Code -> Download ZIP, or use the git command line.
After modifying the code, you can install the modified package by using the command line:

python setup.py install

Or, you can link to the path for convenient modification, eg. sys.path.append(.your file path/), and then import.

Import and quickly predict

import CEEMDAN_LSTM as cl
cl.quick_keras_predict(data=None) # default dataset: sse_index.csv
Load dataset
data = cl.load_dataset() # some built-in dataset eg. sp500.csv hsi.csv ftse.csv nsdaq.csv n225.csv
# data = pd.read_csv(your_file_path + its_name + '.csv', header=0, index_col=['date'], parse_dates=['date'])

Help and example

You can use the code to call for help. You can copy the code from the output of cl.show_keras_example() to run forecasting and help you learn more about the code.

cl.help()
cl.show_keras_example()
cl.show_keras_example_model()
cl.details_keras_predict(data=None)

Start to Forecast

Take Class: keras_predictor() as an example.

Brief summary and forecast

data = cl.load_dataset()
series = data['close'] # choose a DataFrame column 
cl.statis_tests(series)
kr = cl.keras_predictor()
df_result = kr.hybrid_keras_predict(data=series, show=True, plot=True, save=True)

0. Statistical tests (not necessary)

The code will output the results of the ADF test, Ljung-Box Test, and Jarque-Bera Test, and plot ACF and PACF figures to evaluate stationarity, autocorrelation, and normality.

cl.statis_tests(series=None)

1. Declare the parameters

Note, when declaring the PATH, folders will be created automatically, including the figure and log folders.

kr = cl.keras_predictor(PATH=None, FORECAST_HORIZONS=30, FORECAST_LENGTH=30, KERAS_MODEL='GRU', 
                        DECOM_MODE='CEEMDAN', INTE_LIST='auto', REDECOM_LIST={'co-imf0':'ovmd'},
                        NEXT_DAY=False, DAY_AHEAD=1, NOR_METHOD='minmax', FIT_METHOD='add', 
                        USE_TPU=False, **kwargs))
HyperParameters Description
PATH the saving path of figures and logs, eg. ‘D:/CEEMDAN_LSTM/’
FORECAST_HORIZONS the length of each input row(x_train.shape), which means the number of previous days related to today, also called Timestep, Forecast_horizons, or Sliding_windows_length in some papers
FORECAST_LENGTH the length of the days to forecast (test set)
KERAS_MODEL the Keras model, eg. ‘GRU’, ‘LSTM’, ‘DNN’, ‘BPNN’, model = Sequential(), or load_model.
DECOM_MODE the decomposition method, eg.‘EMD’, ‘EEMD’, ‘CEEMDAN’, ‘VMD’, ‘OVMD’, ‘SVMD’
INTE_LIST the integration list, eg. ‘auto’, pd.Dataframe, (int) 3, (str) ‘233’, (list) [0,0,1,1,1,2,2,2], …
REDECOM_LIST the re-decomposition list, eg. ‘{‘co-imf0’:‘vmd’, ‘co-imf1’:‘emd’}’, pd.DataFrame
NEXT_DAY set True to only predict the next out-of-sample value
DAY_AHEAD define to forecast n days’ ahead, eg. 0, 1, 2 (default int 1)
NOR_METHOD the normalizing method, eg. ‘minmax’-MinMaxScaler, ‘std’-StandardScaler, otherwise without normalization
FIT_METHOD the fitting method to stabilize the forecasting result (not necessarily useful), eg. ‘add’, ‘ensemble’ (there some error for ensembleFIT_METHOD, please use add method as default.)
USE_TPU change Keras model to TPU model (for Google Colab)
Keras Parameters Description (more details refer to https://keras.io)
epochs training epochs/iterations, eg. 30-1000
dropout dropout rate of 3 dropout layers, eg. 0.2-0.5
units the units of network layers, which (3 layers) will set to 4units, 2units, units, eg. 4-32
activation activation function, all layers will be the same, eg. ‘tanh’, ‘relu’
batch_size training batch_size for parallel computing, eg. 4-128
shuffle whether randomly disorder the training set during the training process, eg. True, False
verbose report of the training process, eg. 0 not displayed, 1 detailed, 2 rough
valid_split proportion of validation set during the training process, eg. 0.1-0.2
opt network optimizer, eg. ‘adam’, ‘sgd’
opt_lr optimizer learning rate, eg. 0.001-0.1
opt_loss optimizer loss, eg. ‘mse’,‘mae’,‘mape’,‘hinge’, refer to https://keras.io/zh/losses/.
opt_patience optimizer patience of adaptive learning rate, eg. 10-100
stop_patience early stop patience, eg. 10-100

2. Forecast

You can try the following forecasting methods. Note, kr. is the class defined in step 1, necessary for the code.

df_result = kr.single_keras_predict(data, show=True, plot=True, save=True)
# df_result = kr.ensemble_keras_predict(data, show=True, plot=True, save=True)
# df_result = kr.respective_keras_predict(data, show=True, plot=True, save=True)
# df_result = kr.hybrid_keras_predict(data, show=True, plot=True, save=True)
# df_result = kr.multiple_keras_predict(data, show=True, plot=True, save=True)
Forecast Method Description
Single Method Use Keras model to directly forecast with vector input
Ensemble Method Use decomposition-integration Keras model to directly forecast with matrix input
Respective Method Use decomposition-integration Keras model to respectively forecast each IMFs with vector input
Hybrid Method Use the ensemble method to forecast high-frequency IMF and the respective method for other IMFs.
Multiple Method Multiple runs of the above method
Rolling Method Rolling run of the above method to avoid the look-ahead bias, but take a long long time

3. Validate

(1) Plot heatmap

You need to install seaborn first, and the input should be 2D-array.

cl.plot_heatmap(data, corr_method='pearson', fig_path=None)
(2) Diebold-Mariano-Test (DM test)

DM test will output the DM test statistics and its p-value. You can refer to https://github.com/johntwk/Diebold-Mariano-Test.

rt = cl.dm_test(actual_lst, pred1_lst, pred2_lst, h=1, crit="MSE", power=2)

4. Next-day Forecast

Set NEXT_DAY=True.

kr = cl.keras_predictor(NEXT_DAY=True)
df_result = kr.hybrid_keras_predict(data, show=True, plot=True, save=True)
# df_result = kr.rolling_keras_predict(data, predict_method='single')

Sklearn Forecast

You can try the following forecasting methods. Note, sr. is the defined class, necessary for the code.

# SKLEARN_MODEL = LASSO, SVM, or LGB(LightGBM); OPTIMIZER = Bayes, GS(GridSearch)
sr = cl.sklearn_predictor(PATH=path, FORECAST_HORIZONS=30, FORECAST_LENGTH=30,
                          SKLEARN_MODEL='LASSO', OPTIMIZER='Bayes',
                          DECOM_MODE='OVMD', INTE_LIST='auto')
df_result = sr.single_sklearn_predict(data, show=True, plot=True, save=True)
# df_result = sr.respective_sklearn_predict(data, show=True, plot=True, save=True)
# df_result = sr.multiple_sklearn_predict(series_close, run_times=10, predict_method='single')

Discussion

1. Look-ahead bias

As the predictor will decompose the entire series first before splitting the training and test set, there is a look-ahead bias. It is still an issue about how to avoid the look-ahead bias.

2. VMD decompose

The vmdpy module can only decompose the even-numbered length time series. When forecasting an odd-numbered length one, this module will delete the oldest data point. It is still an issue how to modify VMD decomposition. Moreover, selecting the K parameters is important for the VMD method, and hence, I will add some methods to choose a suitable K, such as OVMD, REI, SampEn, and so on.

3. Rolling forecasting

Rolling forecasting costs a lot of time. Like a 30-forecast-length prediction, it will run 30 times cl.hybrid_keras_predict(), so I am not sure if it is really effective or not.

评论

暂无评论