The accurate prediction of solid-solid structural phase transitions at finite temperature is a challenging task, since the dynamics is so slow that direct simulations of the phase transitions by first-principles (FP) methods are typically not possible. Here, we study the $alpha$-$beta$ phase transition of Zr at ambient pressure by means of on-the-fly machine-learned force fields. These are automatically generated during FP molecular dynamics (MD) simulations without the need of human intervention, while retaining almost FP accuracy. Our MD simulations successfully reproduce the first-order displacive nature of the phase transition, which is manifested by an abrupt jump of the volume and a cooperative displacement of atoms at the phase transition temperature. The phase transition is further identified by the simulated x-ray powder diffraction, and the predicted phase transition temperature is in reasonable agreement with experiment. Furthermore, we show that using a singular value decomposition and pseudo inversion of the design matrix generally improves the machine-learned force field compared to the usual inversion of the squared matrix in the regularized Bayesian regression.