In this study, a random forest model optimised based on the sparrow search algorithm is explored for the music genre classification problem. By introducing the sparrow search algorithm, the model is able to search the feature space more comprehensively during the training process, which improves the learning ability of complex data relationships. After 15 iterations of optimisation, the fitness value of the model is improved from 0.2002 to 0.197, showing better convergence. The performance on the training set shows that the model predicts 2,543 music genres with an accuracy of 99.59% and only 10 incorrect predictions, which verifies its excellent performance on the training data. While on the test set, the model's prediction accuracy for 623 music genres is 79.78%, which is slightly lower than the result of the training set, but still reflects good generalisation ability. The results of this paper imply that the improved random forest model based on the sparrow search algorithm has potential application prospects in the music genre classification task. By optimising the parameter settings and feature selection, we not only improve the prediction accuracy and generalisation ability of the model, but also provide new ideas for solving other complex data classification problems. In the future, we can further expand the sample size, try different feature combinations, and conduct in-depth research by combining more domain knowledge in order to further improve the model performance and promote the development of related fields.