Note: This is a practical machine learning project (with data + code + documents + video explanations ). If you need data + code + documents + video explanations, you can go directly to the end of the article to get it.
1.Project background
Hunter-prey optimizer (HPO) is a latest 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 update method based on the location movement of hunters and prey. .
This project optimizes the Catboost classification model through the HPO hunter prey optimization algorithm.
2. Data acquisition
The modeling data for this time comes from the Internet (compiled by the author of this project). The statistics of the data items are as follows:
The data details are as follows (partially displayed):
3. Data preprocessing
3.1 Use Pandas tool to view data
Use the head() method of the Pandas tool to view the first five rows of data:
Key code:
3.2 Viewing missing data
Use the info() method of the Pandas tool to view data information:
As you can see from the picture above, there are a total of 11 variables, no missing values in the data, and a total of 1,000 pieces of data.
Key code:
3.3 Data descriptive statistics
Use the describe() method of the Pandas tool to view the mean, standard deviation, minimum value, quantile, and maximum value of the data.
The key code is as follows:
4. Exploratory data analysis
4.1 y variable histogram
Use the plot() method of the Matplotlib tool to draw a histogram:
4.2 y=1 sample x1 variable distribution histogram
Use the hist() method of the Matplotlib tool to draw a histogram:
4.3 Correlation analysis
As can be seen from the figure above, the larger the value, the stronger the correlation. Positive values are positive correlations, and negative values are negative correlations.
5. Feature engineering
5.1 Establish feature data and label data
The key code is as follows:
5.2 Data set splitting
The train_test_split() method is used to divide 80% of the training set and 20% of the test set. The key code is as follows:
6. Construct HPO hunter prey optimization algorithm to optimize CATBOOST classification model
The HPO hunter prey optimization algorithm is mainly used to optimize the CATBOOST classification algorithm for target classification.
6.1 HPO Hunter-Prey Optimization Algorithm Finds Optimal Parameter Values
Optimal parameters:
6.2 Model construction with optimal parameter values
7. Model evaluation
7.1 Evaluation indicators and results
The evaluation indicators mainly include accuracy rate, precision rate, recall rate, F1 score, etc.
As can be seen from the table above, the F1 score is 0.9231, indicating that the model is effective.
The key code is as follows:
7.2 Classification report
As can be seen from the above figure, the F1 score for classification 0 is 0.94; the F1 score for classification 1 is 0.92.
7.3 Confusion matrix
As can be seen from the above figure, there are 7 samples that are actually 0 and are not predicted to be 0; there are 7 samples that are actually 1 and are not predicted to be 1. The overall prediction accuracy is good.
8. Conclusion and outlook
In summary, this paper uses the HPO hunter-prey optimization algorithm to find the optimal parameter values of the CATBOOST algorithm to build a classification model, which ultimately proves that the model we proposed works well. This model can be used for predictions 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 practical projects, please see the list of practical machine learning projects: