Objective In recent years, the increase in traffic accidents has emerged as a significant social issue that poses a serious threat to public safety. The objective of this study is to predict risky driving scenarios to improve road safety. Methods On the basis of data collected from naturalistic driving real-vehicle experiments, a comprehensive framework for identifying and analyzing risky driving scenarios, which combines an integrated lane-changing detection model and an attention-based long short-term memory (LSTM) prediction model, is proposed. The performance of the 4 machine learning methods on the CULane data set is compared in terms of model running time and running speed as evaluation metrics, and the ultrafast network with the best performance is selected as the method for lane line detection. We compared the performance of LSTM and attention-based LSTM on the basis of the prediction accuracy, recall, precision, and F1 value and selected the better model (attention-based LSTM) for risky scenario prediction. Furthermore, Shapley additive explanation analysis (SHAP) is used to understand and interpret the prediction results of the model. Results In terms of algorithm efficiency, the running time of the ultrafast lane detection network only requires 4.1 ms, and the average detection speed reaches 131 fps. For prediction performance, the accuracy rate of attention-based LSTM reaches 96%, the precision rate is 98%, the recall rate is 96%, and the F1 value is 97%. Conclusions The improved attention-based LSTM model is significantly better than the LSTM model in terms of convergence speed and prediction accuracy and can accurately identify risky scenarios that occur during driving. The importance of factors varies by risky scenario. The characteristics of the yaw rate, speed stability, vehicle speed, acceleration, and lane change significantly influence the driving risk, among which lane change has the greatest impact. This study can provide real-time risky scenario prediction, warnings, and scientific decision guidance for drivers.