Python implements HBA hybrid bat intelligent algorithm to optimize Catboost classification model (CatBoostClassifier 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.< strong>Project Background

The bat algorithm is a heuristic search algorithm proposed by Professor Yang based on swarm intelligence in 2010, and it is an effective method for searching the global optimal solution. Based on iterative optimization, the algorithm is initialized to a set of random solutions, and then iteratively searches for the optimal solution, and generates local new solutions by random flight around the optimal solution to enhance the local search speed. The algorithm has the characteristics of simple implementation and few parameters.

In view of the defects of the basic bat algorithm such as slow convergence speed, easy to fall into local optimum, and low solution accuracy, a hybrid bat algorithm combined with local search is proposed to solve unconstrained optimization problems. The algorithm uses the chaotic sequence to initialize the position and speed of the bat, which lays the foundation for the diversity of the global search; integrates Powell search to enhance the local search ability of the algorithm and speed up the convergence speed; uses the mutation strategy to avoid the algorithm from falling into the local optimum to a certain extent. excellent.

This project optimizes the Catboost classification model through the HBA hybrid bat intelligence algorithm.

2.< strong>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< /strong>

3.1 Use P andasTool View Data

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 above figure, there are a total of 9 variables, no missing values in the data, and a total of 1000 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.< strong>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. A positive value is a positive correlation, and a negative value is a negative correlation.

5.Feature Engineering

5.1 Create feature data and label data

The key code is as follows:

5.2 Dataset Split< /strong>

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

6. Construct HBA hybrid bat optimization algorithm to optimize CATBOOST classification model

Mainly use the HBA hybrid bat optimization algorithm to optimize the CATBOOST classification algorithm for object classification.

6.1 HBA hybrid bat optimization algorithm to find the optimal parameter value

Optimal parameters:

6.2 Optimal parameter value construction model

7. Model Evaluation

7.1 Evaluation indicators and results

Evaluation indicators mainly include accuracy rate, precision rate, recall rate, F1 score and so on.

It can be seen from the above table that the F1 score is 0.8925, indicating that the model works well.

The key code is as follows:

7.2 Classification Report

As can be seen from the above figure, the F1 score of classification 0 is 0.91; the F1 score of classification 1 is 0.89.

7.3 Confusion Matrix

As can be seen from the above figure, there are 10 samples that are actually 0 and predicted to be not 0; there are 10 samples that are actually 1 and predicted to be not 1, and the overall prediction accuracy is good.

8.Conclusions and Outlook< /strong>

To sum up, this paper uses the HBA hybrid bat intelligent optimization algorithm to find the optimal parameter value of the Catboost algorithm to build a classification model, and finally proves that the model we proposed works well. This model can be used for forecasting of everyday products.

for t in range(N_gen):
    print('**********************The current number of iterations is:', t + 1, '************ *******************')

    # Loop over all bats/positions
    for i in range(N_pop):
        Q[i] = np.random.uniform(Qmin, Qmax) # generate random numbers
        v[i] = v[i] + (Sol[i] - best) * Q[i] # speed
        S[i] = Sol[i] + v[i] # position


# *************************************************** *******************************
 
# The materials required for the actual combat of this machine learning project, the project resources are as follows:
 
# project instruction:
 
# Link: https://pan.baidu.com/s/1c6mQ_1YaDINFEttQymp2UQ
 
# Extract code: thgk
 
# *************************************************** *******************************


# y=1 sample x1 variable distribution histogram
fig = plt.figure(figsize=(8, 5)) # set the canvas size
plt.rcParams['font.sans-serif'] = 'SimHei' # set Chinese display
plt.rcParams['axes.unicode_minus'] = False # Solve the problem that the negative sign '-' is displayed as a square in the saved image
data_tmp = df.loc[df['y'] == 1, 'x1'] # filter out samples with y=1
# Draw a histogram bins: control the number of intervals in the histogram auto is the number of automatic filling color: specify the filling color of the column
plt.hist(data_tmp, bins='auto', color='g')

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

List of actual combat collections of machine learning projects

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge Algorithm skill treeHome pageOverview 50021 people are studying systematically

syntaxbug.com © 2021 All Rights Reserved.