Fundamentally, the heat source in the ball screw feed system accounts for the thermal behavior of the ball screw. Based on the analysis of the contribution of each heat source in the system to the thermal deformation of the ball screw, this paper sets out to provide a new method for thermal error compensation. It aims to explore the thermal deformation of ball screw and optimize the distribution of heat source contribution so as to provide theoretical guidance for the cooling of ball screw heat source. Firstly, the relationship between heat source and temperature, temperature and thermal deformation is analyzed theoretically, for the sake of illuminating the relationship between heat source and thermal deformation and the further deduction of the implicit mathematical expression of heat source contribution. Secondly, the network model of ball screw thermal deformation and temperature at the heat source is constructed based on wavelet neural network (WNN). Combined with the mathematical analysis results, the explicit mathematical expression of thermal deformation and heat source under this working condition is deduced, and the explicit mathematical expression of heat source contribution is further obtained. After that, keeping the total heat source contribution constant under this working condition, the particle swarm optimization (PSO) algorithm is used to determine the heat source contribution distribution that can minimize the thermal deformation of the ball screw. Finally, the simulation results of ball screw temperature field and thermal deformation before and after optimization are analyzed to examine the rationality and accuracy of the optimization results.