The frequent fluctuation of pork prices has seriously affected the sustainable development of the pork industry. The accurate prediction of pork prices can not only help pork practitioners make scientific decisions but also help them to avoid market risks, which is the only way to promote the healthy development of the pork industry. Therefore, to improve the prediction accuracy of pork prices, this paper first combines the Sparrow Search Algorithm (SSA) and traditional machine learning model, Classification and Regression Trees (CART), to establish an SSA-CART optimization model for predicting pork prices. Secondly, based on the Sichuan pork price data during the 12th Five-Year Plan period, the linear correlation between piglet, corn, fattening pig feed, and pork price was measured using the Pearson correlation coefficient. Thirdly, the MAE fitness value was calculated by combining the validation set and training set, and the hyperparameter “MinLeafSize” was optimized via the SSA. Finally, a comparative analysis of the prediction performance of the White Shark Optimizer (WSO)-CART model, CART model, and Simulated Annealing (SA)-CART model demonstrated that the SSA-CART model has the best prediction of pork price (compared with a single decision tree, R2 increased by 9.236%), which is conducive to providing support for pork price prediction. The accurate prediction of pork prices with an optimized machine learning model is of great practical significance for stabilizing pig production, ensuring the sustainable growth of farmers’ income, and promoting sound economic development.