Machine learning algorithms can learn the rules and patterns of big data through computers, excavate potential information hidden behind the data, and be widely used to solve classification, regression, clustering, and other problems. Firstly, this paper uses CORSIKA software to simulate the process of cosmic ray cascade shower in the atmosphere, generating information such as the initial energy, zenith angle, azimuth angle of cosmic ray particles. Then, this paper uses the Geant4 toolkit to conduct thermal neutron detector response simulation, generating 4000 particles in each of proton, helium, CNO, MgAlSi and iron. Based on the experimental simulation data of thermal neutron detector, this paper constructs machine learning models for identifying cosmic ray particles by using decision tree (DT), random forest (RF) and BP neural network (BP NN) respectively. For each particle, all the machine learning algorithms are used for model training based on the simulation data. The cross grid search method is used to adjust the hyper parameters of each machine learning algorithm. The AUC value and <i>Q</i> quality factor value of each algorithm are used as evaluation indexes for particle composition identification. The AUC value is a general indicator for evaluating algorithm performance in machine learning and the <i>Q</i> quality factor value is an evaluation index commonly used in the field of high energy physics. The Experimental results show that different machine learning models have great influence on particle prediction accuracy, and the random forest cosmic ray particle identification model has sufficient accuracy and generalization capability. In the test, the decision tree algorithm adjusted by cross grid search method is sensitive to the medium components (CNO and MgAlSi). The AUC values of the algorithm are all above 0.95 and the <i>Q</i> quality factor values are all above 6. The random forest algorithm adjusted by the cross grid search method has the best effect on the identification of cosmic ray particles. The AUC values of the algorithm are all more than 0.92 and the <i>Q</i> quality factor values are all more than 4. The BP neural network algorithm is only sensitive to proton and iron. This study provides a new method and selection for identifying and screening the cosmic ray particles and it also provides a new idea for the following measurement of cosmic ray energy spectrum by thermal neutron detector.