Dangerous driving behaviours contribute significantly to road accidents. Researchers have developed numerous models for predicting dangerous behaviours. However, these models have remained at the development stage. This paper proposes using a dynamic weight moving average (DWMA) method for processing heart rate variability (HRV) indices and establishing prediction models using long short-term memory (LSTM) networks. The changes in HRV indices between baseline and pre-event stages were also investigated. Thirty-three Taiwanese commercial drivers, which were 19 urban drives and 14 highway drivers, were recruited (between September 2019 and June 2020). Their driving behaviours and physiological signals during tasks were obtained by navigation software and an HRV watch. The DWMA and exponential moving average were applied to process the physiological signals. The derived data set was split into training and testing sets (ratio: 80% to 20%). To establish the models, the LSTM networks were trained using the training set and K-fold cross-validation (K = 10). Prediction performance was evaluated by sensitivity, specificity, and accuracy. For the urban drivers, the significantly raised values in the normalized low-frequency spectrum and the sympathovagal balance index were found. The significantly elevated values in the standard deviation of NN intervals were observed. For the highway drivers, the significantly increased heart rate and root mean square of successive RR interval differences can be observed. Besides, the LSTM models based on DWMA demonstrated the highest accuracy in urban and highway groups (Urban driving group: 80.31%, 95% confidence interval: 84.65-91.71%; Highway driving group: 80.70%, 95% confidence interval: 72.25-87.49%). The authors recommend using these models to prevent dangerous driving behaviours.