The seismic time history plays a crucial role in pre-earthquake risk assessment and post-earthquake damage evaluation. However, due to the uncertainty in simulating seismic motion parameters, there can be notable differences between simulation results and actual records. Fortunately, advancements in data mining techniques and the availability of high-quality strong motion observation records have made it possible to simulate earthquakes by extracting seismic characteristic records. In this study, we utilized the principal component analysis method from machine learning to extract the characteristic principal component time history of the Luding 5.0 earthquake. This extracted data was then used to simulate the seismic time history of the mainshock, which was a 6.8 magnitude earthquake in Luding. To ensure accuracy, the simulation process incorporated the peak acceleration and response spectrum of the seismic motion at the target station of the mainshock as constraint conditions. By employing the particle swarm optimization algorithm, we calculated the combination coefficients of the characteristic principal component time history to simulate the mainshock. The results of this simulation were found to be consistent with actual records, providing valuable insights for studying the potential impact of strong earthquakes in regions prone to frequent small and medium-sized earthquakes.