In order to improve the psychological state of miners, improve the safety behavior of miners, and effectively prevent and control coal mine accidents, the questionnaire was used to investigate the unsafe psychology of frontline employees in Shanxi a coal mine and Shaanxi B coal mine. The fluke mentality, conformity mentality and shortcut energy saving mentality of unsafe psychology was selected by reading literature, the mediating variables of safety awareness and team safety atmosphere were selected, and the correlation analysis and the K-means were carried out on the data using python. Found that miners fluke mentality has the greatest negative impact on safety behavior, followed by conformity mentality, and shortcut energy saving mentality is the least, the indirect positive influence of miners' unsafe psychology on safety behavior through team safety atmosphere is greater than safety awareness, miners classified as three types according to the clustering results, provide a reference for coal mining enterprises to improve the miners' safety behavior accurately.