Python implements FA firefly optimization algorithm to optimize Catboost classification model (CatBoostClassifier algorithm) project practice

Note: This is amachine learning practical project (comes with data + code + documentation + video Explanation), if you needdata + code + documentation + video explanation, you can go directly to the end of the article to get it.

1.Item background

Fire-fly algorithm (FA) was proposed by Yang of Cambridge University in 2009. As one of the latest swarm intelligence optimization algorithms, this algorithm has the advantages of better convergence speed and convergence accuracy, and is easy to implement in engineering.

This project optimizes the CATBOOST classification model through the FA firefly optimization algorithm.

2.number 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:

serial number 

variable name

describe

1

x1

2

x2

3

x3

4

x4

5

x5

6

x6

7

x7

8

x8

9

x9

10

x10

11

and

dependent variable

The data details are as follows (partially displayed):

3.Data preprocessing

3.1 用PandasTools

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

Key code:

3.2 View with 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 2,000 pieces of data.

Key code:  

3.3Number prescriptiveness calculation 

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.1y change column pattern 

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 Compatibility 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.Special expedition process

5.1 Create feature data and label data

The key code is as follows:

5.2 Dataset 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 FA firefly optimization algorithm to optimize CATBOOST classification model

The FA firefly optimization algorithm is mainly used to optimize the CATBOOST classification algorithm for target classification.

6.1 FA Firefly Optimization Algorithm Finds Optimal Parameter Values   

Optimal parameters:

   

6.2 Build model with optimal parameter values

serial number

Model name

parameter

1

CATBOOST classification model

depth=int(abs(best_depth))

2

learning_rate=best_learning_rate

7. Model evaluation

7.1 Evaluation indicators and results

Evaluation indicators mainly include accuracy, precision, recall, F1 score, etc.

Model name

Indicator name

Index value

test set

CATBOOST classification model

Accuracy

0.8850

precision

0.8663

recall rate

0.9021

F1 score

0.8838

As can be seen from the table above, the F1 score is 0.8838, 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.89; the F1 score for classification 1 is 0.88.

7.3 Confusion matrix

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

8.Conclusion outlook

To sum up, this paper uses the FA firefly 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.


# 本次机器学习项目实战所需的资料,项目资源如下:
 
# 项目说明:

链接:https://pan.baidu.com/s/1paxPUgUgf6UWwMLI2ZdUqQ 
提取码:1xch

For more practical projects, please see the list of practical machine learning projects:

Machine learning project practical collection list_Machine learning practical project_Pang Ge’s really good blog-CSDN blog


 

Guess you like

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