Regression prediction | MATLAB implements SSA-CNN-LSTM sparrow algorithm to optimize convolutional long-term short-term memory neural network multi-input single-output regression prediction

Regression prediction | MATLAB implements SSA-CNN-LSTM sparrow algorithm to optimize convolutional long-term short-term memory neural network multi-input single-output regression prediction

predictive effect

1
2

3
4
5
6

7

basic introduction

MATLAB implements SSA-CNN-LSTM sparrow algorithm to optimize convolutional long-term short-term memory neural network multi-input single-output regression prediction, and the operating environment is Matlab2020b and above. Optimize regularization rate, learning rate, number of hidden layer units.
1. Matlab implements SSA-CNN-LSTM sparrow algorithm to optimize convolutional long-term short-term memory network (CNN-LSTM) multiple-input single-output regression prediction
2. Input multiple features, output a single variable, and multiple-input single-output regression prediction;
3. Multiple Index evaluation, evaluation indicators include: R2, MAE, MSE, RMSE, etc., code quality is extremely high;
4. Sparrow algorithm optimization parameters are: learning rate, hidden layer nodes, regularization parameters;
5.excel data, easy to replace, run Environment 2020 and above.

Model description

The sparrow search algorithm is a swarm intelligence optimization algorithm. In the sparrow foraging process, it is divided into discoverers and joiners. The discoverer is responsible for finding food in the population and providing foraging areas and directions for the entire sparrow population, while the joiners are It is to use the finder to obtain food. In order to obtain food, sparrows can usually adopt two behavioral strategies of finder and joiner to forage. Individuals in the population monitor the behavior of other individuals in the population, and attackers in the population compete for food resources with high-intake peers to increase their predation rate. In addition, sparrow populations engage in anti-predation behavior when attacked by predators.

6

Deep learning network structure based on convolutional neural network and long short-term memory (LSTM) neural network. Using the method of feature fusion, the shallow features and deep features are extracted and connected through the convolutional network, the features are fused through convolution, and the obtained vector information is input into the LSTM unit.

programming

%%  获取最优种群
   for j = 1 : SearchAgents
       if(fitness_new(j) < GBestF)
          GBestF = fitness_new(j);
          GBestX = X_new(j, :);
       end
   end
   
%%  更新种群和适应度值
   pop_new = X_new;
   fitness = fitness_new;

%%  更新种群 
   [fitness, index] = sort(fitness);
   for j = 1 : SearchAgents
      pop_new(j, :) = pop_new(index(j), :);
   end

%%  得到优化曲线
   curve(i) = GBestF;
   avcurve(i) = sum(curve) / length(curve);
end

%%  得到最优值
Best_pos = GBestX;
Best_score = curve(end);

%%  得到最优参数
NumOfUnits       =abs(round( Best_pos(1,3)));       % 最佳神经元个数
InitialLearnRate =  Best_pos(1,2) ;% 最佳初始学习率
L2Regularization = Best_pos(1,1); % 最佳L2正则化系数
% 
inputSize = k;
outputSize = 1;  %数据输出y的维度  
%  参数设置
opts = trainingOptions('adam', ...                    % 优化算法Adam
    'MaxEpochs', 20, ...                              % 最大训练次数
    'GradientThreshold', 1, ...                       % 梯度阈值
    'InitialLearnRate', InitialLearnRate, ...         % 初始学习率
    'LearnRateSchedule', 'piecewise', ...             % 学习率调整
    'LearnRateDropPeriod', 6, ...                     % 训练次后开始调整学习率
    'LearnRateDropFactor',0.2, ...                    % 学习率调整因子
    'L2Regularization', L2Regularization, ...         % 正则化参数
    'ExecutionEnvironment', 'gpu',...                 % 训练环境
    'Verbose', 0, ...                                 % 关闭优化过程
    'SequenceLength',1,...
    'MiniBatchSize',10,...
    'Plots', 'training-progress');                    % 画出曲线

summarize

The sparrow algorithm is a prediction model based on convolutional neural network (CNN) and long-term short-term memory neural network (LSTM), which can be used for regression prediction tasks with multiple inputs and single outputs, such as mahjong prediction.
The flow of the algorithm is as follows:
data preprocessing. Preprocess the input data, such as converting card type data into numbers, normalizing, filling missing values, etc.
convolutional network. The input data is processed by convolutional neural network (CNN) to extract its feature representation.
LSTM network. The feature sequence extracted by the convolutional network is input into a long short-term memory neural network (LSTM) to convert it into a single output.
output. Output the prediction results of the LSTM network.
In this algorithm, the convolutional network is used to extract the features of the input data, and the LSTM network converts the feature sequence extracted by the convolutional network into a single output and retains its time series information, so that it can better predict future results.
The optimization method of this algorithm mainly focuses on two stages of convolutional network and LSTM network:
convolutional network optimization. By increasing the depth and width of the convolutional network, its expressive ability can be increased, and the feature extraction ability of the input sequence can be improved. At the same time, better activation functions and regularization methods, such as ReLU and Dropout, can be used to increase the nonlinear ability and generalization ability of the network.
LSTM network optimization. By increasing the hidden layer size and number of layers of the LSTM network, its expression ability and memory ability can be increased, and the modeling ability of the input sequence can be improved. At the same time, better gating mechanism and gradient clipping methods, such as LSTM and Clip Gradient, can be used to increase the stability and generalization ability of the network.
In short, the sparrow algorithm is a prediction model based on deep learning. Through the combination of convolutional neural network and long-term short-term memory neural network, it can model and predict the regression prediction task with multiple inputs and single outputs. Its optimization methods mainly include adjusting model structure, optimizing loss function and optimization algorithm, fusing multiple data sources, increasing data preprocessing and enhancement, and adjusting model hyperparameters. Through these optimization methods, the predictive performance and generalization ability of the model can be improved to adapt to a wider range of application scenarios.

References

[1] https://blog.csdn.net/kjm13182345320/article/details/128577926?spm=1001.2014.3001.5501
[2] https://blog.csdn.net/kjm13182345320/article/details/128573597?spm=1001.2014.3001.5501

Guess you like

Origin blog.csdn.net/kjm13182345320/article/details/130920876