Python implements the hunter-prey optimization algorithm (HPO) to optimize the cyclic neural network regression model (LSTM regression algorithm) project combat

Explanation: This is a machine learning practical project (with data + code + documentation + video explanation ). If you need data + code + documentation + video explanation, you can go directly to the end of the article to get it.




1. Project Background

Hunter–prey optimizer (HPO) is a newest optimization search algorithm proposed by Naruei & Keynia in 2022. Inspired by the behavior of predators (such as lions, leopards, and wolves) and prey (such as stags and gazelles), they designed a new search method and adaptive degree update method based on the position movement method of the hunter and prey .

This project uses the HPO hunter-prey optimization algorithm to find the optimal parameter values ​​to optimize the LSTM regression model.

2. Data acquisition

The modeling data for this time comes from the Internet (compiled by the author of this project), and the statistics of the data items are as follows:

The data details are as follows (partial display):

3. Data preprocessing

3.1 View data with Pandas tools

Use the head() method of the Pandas tool to view the first five rows of data:

key code:

3.2 Data missing view

Use the info() method of the Pandas tool to view data information:

As can be seen from the figure above, there are a total of 11 variables, no missing values ​​in the data, and a total of 2000 data.

key code:  

3.3 Data descriptive statistics

Use the describe() method of the Pandas tool to view the mean, standard deviation, minimum, quantile, and maximum of the data.

The key code is as follows:    

4. Exploratory Data Analysis

4.1 Histogram of y variables

Use the hist() method of the Matplotlib tool to draw a histogram:

As can be seen from the figure above, the y variable is mainly concentrated between -400 and 400.

4.2 Correlation analysis

As can be seen from the figure above, the larger the value, the stronger the correlation. A positive value is a positive correlation, and a negative value is a negative correlation.

5. Feature engineering

5.1 Establish feature data and label data

The key code is as follows:

5.2 Dataset splitting

Use the train_test_split() method to divide according to 80% training set and 20% test set. The key code is as follows:

5.3 Data sample dimension increase

The data shape of the data sample after adding dimensions:

6. Build the HPO hunter-prey optimization algorithm to optimize the LSTM regression model

Mainly use the HPO hunter-prey optimization algorithm to optimize the LSTM regression algorithm for target regression.

6.1 Optimal parameters found by HPO hunter-prey optimization algorithm

key code:

Optimal parameters:

  

6.2 Optimal parameter value construction model

6.3 Optimal parameter model summary information

6.4 Optimal parameter model network structure

6.5 Optimal parameter model training set test set loss curve

7. Model Evaluation

7.1 Evaluation indicators and results

The evaluation indicators mainly include explainable variance value, mean absolute error, mean square error, R square value and so on.

It can be seen from the above table that the R square is 0.9989, which means that the model has a better effect.

The key code is as follows:

7.2 Comparison chart of actual value and predicted value

From the above figure, it can be seen that the fluctuations of the actual value and the predicted value are basically the same, and the model fitting effect is good.  

8. Conclusion and Outlook

To sum up, this paper uses the HPO hunter-prey optimization algorithm to find the optimal parameter values ​​of the LSTM regression algorithm to build a regression model, and finally proves that the model we proposed works well. This model can be used for forecasting of everyday products.

def __init__(self, m, T, lb, ub, R, C, X_train, y_train, X_test, y_test):
    self.M = m  # 种群个数
    self.T = T  # 迭代次数
    self.lb = lb  # 下限
    self.ub = ub  # 上限
    self.R = R  # 行
    self.C = C  # 列
    self.b = 0.1  # 调节参数
 
    self.X_train = X_train  # 训练集特征
    self.X_test = X_test  # 测试集特征
    self.y_train = y_train  # 训练集标签
    self.y_test = y_test  # 测试集标签
 
 
 
# ******************************************************************************
 
# 本次机器学习项目实战所需的资料,项目资源如下:
 
# 项目说明:
 
# 链接:https://pan.baidu.com/s/1-P7LMzRZysEV1WgmQCpp7A 
 
# 提取码:5fv7
 
# ******************************************************************************
 
 
 # 提取特征变量和标签变量
y = df['y']
X = df.drop('y', axis=1)
 
# 划分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
 

For more project practice, see the list of machine learning project practice collections:

List of actual combat collections of machine learning projects


 

Guess you like

Origin blog.csdn.net/weixin_42163563/article/details/132710924