Predicting Credit Degree Based on Random Forest Method of Spark

The fusion learning algorithm combines multiple machine learning algorithms to obtain a better model. Random forest is a commonly used fusion learning method in classification and regression problems. This algorithm builds multiple decision trees based on different subsets of training data and combines them into a new model. The prediction result is a combination of all the output of the decision tree, which can reduce fluctuations and improve the accuracy of the prediction. For the random forest classification model, the prediction result of each tree is regarded as a vote. The category with the most votes is the predicted category.


The final prediction data set in DataFrame format is as follows:


We consider optimizing the parameters of the random forest model from three aspects First, let the number of decision trees participating in the voting remain unchanged, take the depth of the decision tree as the independent variable, train random forest models of different depths, and compare the area AUC of the ROC curve of each model, you can find that the greater the tree depth value is , The higher the AUC, the better the trained model, but it will cost the model training and prolong the training time.

Then, let the depth of the decision tree be a constant value of 3, that is, each tree has at most three layers, train a random forest model with different voting decision trees, and find that when the number of trees participating in the voting is between 20-24, the AUC curve The hinge is high, the trained random forest model is better

Take the number of decision trees participating in voting as the abscissa, the depth of the model tree as the ordinate, and the gray value of the square color to represent AUC. Train 200 random forest models and make data cubes. The more trees there are, the deeper each tree, the higher the gray value of the square, the higher the AUC, and the better the random forest model.