An improved support vector machine model for energy consumption prediction is proposed to achieve efficient energy saving in buildings. In this paper, firstly, a gray correlation analysis model is used to measure the correlation between temperature, humidity, sunlight and other factors and building energy consumption. Secondly, the sparrow search algorithm (SSA) is introduced to optimize the penalty coefficient c and kernel function parameter g of the support vector machine, and then the SSA-SVM energy consumption prediction model is established. Finally, the experimental results are analyzed by comparing with the data derived from the support vector machine prediction (SVM) model and BP neural network energy consumption prediction. The experimental results show that compared with SVM and BP neural network, the prediction results of SSA-SVM model perform better in error index, indicating that the energy consumption prediction of SSA-SVM model has higher prediction accuracy; the maximum relative error of SSA-SVM prediction model is 0.0514, and the maximum relative errors of the other two models are greater than 0.55, indicating that SSA-SVM model has a higher degree of reliability.