Description: 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 Obtain.
1. Project background
Genetic Algorithm (GA) was first proposed by John Holland in the United States in the 1970s. This algorithm is designed and proposed according to the evolution law of organisms in nature. It is a calculation model of the biological evolution process that simulates the natural selection and genetic mechanism of Darwin’s biological evolution theory, and it is a method to search for the optimal solution by simulating the natural evolution process. The algorithm converts the solving process of the problem into a process similar to the crossover and mutation of chromosome genes in biological evolution by means of mathematics and computer simulation operations. When solving more complex combinatorial optimization problems, compared with some conventional optimization algorithms, usually better optimization results can be obtained faster. Genetic algorithm has been widely used in combinatorial optimization, machine learning, signal processing, adaptive control and artificial life and other fields.
This project optimizes the CatBoost regression model through GA genetic algorithm.
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 View missing data
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.1 y variable histogram
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 Create feature data and label data
The key code is as follows:
5.2 Dataset Split
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 GA genetic algorithm to optimize CATBOOST regression model
Mainly use the GA genetic algorithm to optimize the CATBOOST regression algorithm for target regression.
6.1 GA genetic algorithm to find the optimal parameter value
Optimal parameter values:
6.2 Model building with optimal parameter values
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.9818, which is a good model.
The key code is as follows:
7.2 True value and Predicted value comparison chart
It can be seen from the above figure 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 prospect
To sum up, this paper uses the GA genetic algorithm to find the optimal parameter value of the CATBOOST 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.
# Initialize population, initial solution Sol = np.zeros((N_pop, d)) # initial position Fitness = np.zeros((N_pop, 1)) # Initialize fitness for i in range(N_pop): # iteration population Sol[i] = np.random.uniform(Lower_bound, Upper_bound, (1, d)) # generate random numbers Fitness[i] = objfun(Sol[i]) # Fitness # *************************************************** ******************************* # 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 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['y'] # filter out samples of y variable # 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
For project code consultation and acquisition, please refer to the official account below.
The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge algorithm skill tree HomepageOverview 50751 people are learning systematically