The lattice Boltzmann method is employed in the current study to simulate the heat transfer characteristics of sinusoidal-temperature-distributed heat sources at the bottom of a square cavity under various conditions, including different amplitudes, phase angles, initial positions, and angular velocities. Additionally, a machine learning-based model is developed to accurately predict the Nusselt number in such a sinusoidal temperature distribution of heat source at the bottom of a square cavity. The results indicate that (1) in the phase angle range from 0 to π, Nu basically shows a decreasing trend with an increase in phase angle. The decline in Nu at an accelerated rate is consistently observed when the phase angle reaches 4π/16. The corresponding Nu decreases as the amplitude increases at the same phase angle. (2) The initial position of the sinusoidal-temperature-distributed heat source Lc significantly impacts the convective heat transfer in the cavity. Moreover, the decline in Nu was further exacerbated when Lc reached 7/16. (3) The optimal overall heat transfer effect was achieved when the angular velocity of the non-uniform heat source reached π. As the angular velocity increases, the local Nu in the square cavity exhibits a gradual and oscillatory decline. Notably, it is observed that Nu at odd multiples of π surpasses that at even multiples of π. Furthermore, the current work integrates LBM with machine learning, enabling the development of a precise and efficient prediction model for simulating Nu under specific operational conditions. This research provides valuable insights into the application of machine learning in the field of heat transfer.