Football is one of the most popular sports in the world. As the popularity of football continues to grow worldwide, so does the number of incidents of violence on the pitch. Today, doping, match fixing, black whistles, and football hooliganism are ranked as the four most toxic aspects of sport. How to study the factors that cause aggressive behaviour of fans from a psychological perspective has become a key issue in the field of sports. Therefore, this study proposes a method for mining the psychological factors of sport fan community members based on machine learning clustering. Firstly, three different members of a large fan community, i.e., university students, office workers, and unemployed people, are used as research subjects to investigate the psychological factors influencing fans’ aggressive behaviour using a questionnaire method. Secondly, the data obtained were mined and analysed using the K-means clustering algorithm in machine learning techniques. At the same time, a K-means initial clustering centre optimization algorithm based on principal component analysis (PCA) was proposed for the data characteristics of the interaction of psychological factors. The results show that the new algorithm significantly improves the quality of clustering compared with other optimization algorithms and accurately identifies the multiple factors that contribute to the occurrence of fan attacks.