The aim of this study was to establish a correlation model between external surface motion and internal diaphragm apex movement using machine learning and to realize online automatic prediction of the diaphragm motion trajectory based on optical surface monitoring. The optical body surface parameters and kilovoltage (kV) X-ray fluoroscopic images of 7 liver tumor patients were captured synchronously for 50 seconds. The location of the diaphragm apex was manually delineated by a radiation oncologist and automatically detected with a convolutional network model in fluoroscopic images. The correlation model between the body surface parameters and the diaphragm apex of each patient was developed through linear regression (LR) based on synchronous datasets before radiotherapy. Model 1 (M1) was trained with data from the first 30 seconds of the datasets and tested with data from the following 20 seconds of the datasets in the first fraction to evaluate the intra-fractional prediction accuracy. Model 2 (M2) was trained with data from the first 30 seconds of the datasets in the next fraction. The motion trajectory of the diaphragm apex during the following 20 seconds in the next fraction was predicted with M1 and M2, respectively, to evaluate the inter-fractional prediction accuracy. The prediction errors of the 2 models were compared to analyze whether the correlation model needed to be re-established. The average mean absolute error (MAE) and root mean square error (RMSE) using M1 trained with automatic detection location for the first fraction were 3.12±0.80 and 3.82±0.98 mm in the superior-inferior (SI) direction and 1.38±0.24 and 1.74±0.32 mm in the anterior-posterior (AP) direction, respectively. The average MAE and RMSE of M1 versus M2 in the AP direction were 2.63±0.71 versus 1.28±0.48 mm and 3.26±0.90 versus 1.61±0.60 mm, respectively. The average MAE and RMSE of M1 versus M2 in the SI direction were 5.84±1.22 versus 3.37±0.43 mm and 7.22±1.45 versus 4.07±0.54 mm, respectively. The prediction accuracy of M2 was significantly higher than that of M1. This study shows that it is feasible to use optical body surface information to automatically predict the diaphragm motion trajectory. At the same time, it is necessary to establish a new correlation model for the current fraction before each treatment.