使用极限学习机进行股市预测(Matlab代码实现)

简介: 使用极限学习机进行股市预测(Matlab代码实现)

💥1 概述

极限学习机(Extreme Learning Machine,ELM)作为前馈神经网络学习中一种全新的训练框架,在行为识别、情感识别和故障诊断等方面被广泛应用,引起了各个领域的高度关注和深入研究.ELM最初是针对单隐层前馈神经网络的学习速度而提出的,之后又被众多学者扩展到多隐层前馈神经网络中.该算法的核心思想是随机选取网络的输入权值和隐层偏置,在训练过程中保持不变,仅需要优化隐层神经元个数.网络的输出权值则是通过最小化平方损失函数,来求解Moore-Penrose广义逆运算得到最小范数最小二乘解.相比于其它传统的基于梯度的前馈神经网络学习算法,ELM具有实现简单,学习速度极快和人为干预较少等显著优势,已成为当前人工智能领域最热门的研究方向之一.ELM的学习理论表明,当隐层神经元的学习参数独立于训练样本随机生成,只要前馈神经网络的激活函数是非线性分段连续的,就可以逼近任意连续目标函数或分类任务中的任何复杂决策边界.近年来,随机神经元也逐步在越来越多的深度学习中使用,而ELM可以为其提供使用的理论基础.


运行脚本的说明:

  1. 打开 ELM_run.m 脚本并更改脚本参数的值。
  2. 运行脚本

📚2 运行结果

🎉3 参考文献

[1]徐睿,梁循,齐金山,李志宇,张树森.极限学习机前沿进展与趋势[J].计算机学报,2019,42(07):1640-1670.

👨‍💻4 Matlab代码

主函数部分代码:

%%Introduction to the ELM run script
%Please the change the arguments according to your needs
%% important arguments for the script
activationFunction = 'linear';
dataFile = 'newstocks.txt';
rowsToSkip = 1;
columnsToSkipFromLeft = 1; 
columnsToSkipFromRight = 1;
hiddenLayerSize = 10;
trainingPercentage = 50;
daysToPredict = 5;
%% data loading and preprocessing
% load data
pureData = csvread(dataFile,rowsToSkip,columnsToSkipFromLeft);
% acquire X
X = pureData(daysToPredict:end,1:end - columnsToSkipFromRight);
% get number of entries and features
[nEntries, nFeatures] = size(X);
% acquire Y 
Y = pureData(1:nEntries,1:nFeatures);
% finding split points in data
percTraining = trainingPercentage/100; 
endTraining  = ceil(percTraining * nEntries);
% dividing X and Y
% training data 
trainX = X(1:endTraining,:); 
trainY = Y(1:endTraining,:);
% testing data
testX = X(endTraining+1:end,:);
testY = Y(endTraining+1:end,:);
%% creation and training of ELM model
% create ELM
ELM = ELM_MatlabClass(nFeatures,hiddenLayerSize,activationFunction);
% train ELM on the training dataset
ELM = train(ELM,trainX,trainY);
%% validation of ELM model
predictionTest = predict(ELM,testX);
disp('Statistics when predicting on testing data');
fprintf('Testing Rsquare(close to 1 means nice prediction) = %3.3f\n',computeR2(testX,predictionTest));
fprintf('Testing Root mean square error of open price = %3.3f\n',computeRMSE(testX(:,1),predictionTest(:,1)));
fprintf('Testing Root mean square error of high price = %3.3f\n',computeRMSE(testX(:,2),predictionTest(:,2)));
fprintf('Testing Root mean square error of low price = %3.3f\n',computeRMSE(testX(:,3),predictionTest(:,3)));
fprintf('Testing Root mean square error of close price = %3.3f\n',computeRMSE(testX(:,4),predictionTest(:,4)));
% compute and report accuracy on training dataset
predictionTrain = predict(ELM,trainX);
disp('Statistics when predicting on training data');
fprintf('Training Rsquare(close to 1 means nice prediction) = %3.3f\n',computeR2(trainX,predictionTrain));
fprintf('Training Root mean square error of open price = %3.3f\n',computeRMSE(trainX(:,1),predictionTrain(:,1)));
fprintf('Training Root mean square error of high price = %3.3f\n',computeRMSE(trainX(:,2),predictionTrain(:,2)));
fprintf('Training Root mean square error of low price = %3.3f\n',computeRMSE(trainX(:,3),predictionTrain(:,3)));
fprintf('Training Root mean square error of close price = %3.3f\n',computeRMSE(trainX(:,4),predictionTrain(:,4)));
%% sensitivity analysis on number of hidden neurons
hiddenLayerSize    = 1:10:100;
trainR2   = zeros(size(hiddenLayerSize));
testR2   = zeros(size(hiddenLayerSize));
for i = 1 : numel(hiddenLayerSize)
    % create ELM for classification
    ELM = ELM_MatlabClass(nFeatures,hiddenLayerSize(i),activationFunction);
    % train ELM on the training dataset
    ELM = train(ELM,trainX,trainY);
    Yhat = predict(ELM,trainX);
    trainR2(i) = computeR2(trainX,Yhat);
    % validation of ELM model
    Yhat = predict(ELM,testX);
    testR2(i) = computeR2(testX,Yhat);
end
% plot results of accuracy with different sizes of the hidden layer
figure;
plot(hiddenLayerSize,[trainR2;testR2],'-o');
xlabel('Number of Hidden Neurons');
ylabel('R square error');
legend({'training','testing'},'Location','southeast');
相关文章
|
2月前
|
安全
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
本文介绍了2023年高教社杯数学建模竞赛D题的圈养湖羊空间利用率问题,包括问题分析、数学模型建立和MATLAB代码实现,旨在优化养殖场的生产计划和空间利用效率。
123 6
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
|
2月前
|
存储 算法 搜索推荐
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
本文提供了2022年华为杯数学建模竞赛B题的详细方案和MATLAB代码实现,包括方形件组批优化问题和排样优化问题,以及相关数学模型的建立和求解方法。
95 3
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
|
2月前
|
数据采集 存储 移动开发
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
本文介绍了2023年五一杯数学建模竞赛B题的解题方法,详细阐述了如何通过数学建模和MATLAB编程来分析快递需求、预测运输数量、优化运输成本,并估计固定和非固定需求,提供了完整的建模方案和代码实现。
71 0
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
|
5月前
|
数据安全/隐私保护
耐震时程曲线,matlab代码,自定义反应谱与地震波,优化源代码,地震波耐震时程曲线
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
基于混合整数规划的微网储能电池容量规划(matlab代码)
基于混合整数规划的微网储能电池容量规划(matlab代码)
|
5月前
|
算法 调度
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
|
5月前
|
Serverless
基于Logistic函数的负荷需求响应(matlab代码)
基于Logistic函数的负荷需求响应(matlab代码)
|
5月前
|
供应链 算法
基于分布式优化的多产消者非合作博弈能量共享(Matlab代码)
基于分布式优化的多产消者非合作博弈能量共享(Matlab代码)
|
5月前
|
算法 调度
基于多目标粒子群算法冷热电联供综合能源系统运行优化(matlab代码)
基于多目标粒子群算法冷热电联供综合能源系统运行优化(matlab代码)
|
5月前
|
算法 调度 SoC
电动汽车充放电V2G模型(Matlab代码)
电动汽车充放电V2G模型(Matlab代码)

热门文章

最新文章

下一篇
无影云桌面