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 uses the FA firefly optimization algorithm to find optimal parameter values to optimize the random forest regression model.
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 square picture
Use the hist() method of the Matplotlib tool to draw a histogram:
As you can see from the picture 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. 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 random forest regression model
The FA firefly optimization algorithm is mainly used to optimize the random forest regression algorithm for target regression.
6.1 The optimal parameters found by the FA firefly optimization algorithm
Optimal parameters:
6.2 Build model with optimal parameter values
serial number |
Model name |
parameter |
1 |
Random forest regression model |
max_depth=best_max_depth |
2 |
n_estimators=best_n_estimators |
7.Model introduction
7.1 Evaluation indicators and results
Evaluation indicators mainly include explainable variance value, mean absolute error, mean square error, R-squared value, etc.
Model name |
Indicator name |
Index value |
test set |
||
Random forest regression model |
R square |
0.8773 |
mean square error |
2856.772 |
|
explained variance |
0.8773 |
|
mean absolute error |
41.0043 |
As can be seen from the table above, R square is 0.8773, which means the model has good effect.
The key code is as follows:
7.2 Comparison chart between true value and predicted value
It can be seen from the above figure that the fluctuations of the real value and the predicted value are basically consistent, and the model fitting effect is good.
8.Conclusion outlook
To sum up, this article uses the FA firefly optimization algorithm to find the optimal parameter values of the random forest regression algorithm to build a regression 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/14M5y6f0jkmLBzHc7y6TBzg
提取码:tyf5
For more practical projects, please see the list of practical machine learning projects: