Psychological stress is a psychological stress response that occurs when a person is faced with an overwhelming situation. Research has shown that the right level of stress can lead to progress and the realisation of one's potential. For students, appropriate levels of stress can enhance their learning and contribute to their growth and development. However, excessive psychological stress can be physically and psychologically distressing, and can even lead to suicidal behaviour. If students with abnormal psychological stress can be identified in time, schools can provide timely help and intervention to alleviate the psychological stress. The main objective of this paper is to develop a study on the analysis of university students' mental health based on machine learning. To investigate the difference between supervised and unsupervised learning, the LOF algorithm was also introduced for comparison. Experiments show that the G-mean value of ES-ANN improves by approximately 8 percentage points and the F1 value by approximately 4 percentage points over the best benchmark algorithm. Compared to traditional questionnaire-based methods, the daily campus data has a higher degree of authenticity and real time, which helps schools to identify students with high psychological stress in a timely manner. The research in this paper suggests that this idea is potentially feasible and deserves further validation and improvement in practice.