This study aimed to develop a machine learning (ML) model for predicting pulmonary embolism (PE) in patients with gastrointestinal cancers, a group at increased risk for PE. We conducted a retrospective, multicenter study analyzing patients who underwent computed tomographic pulmonary angiography (CTPA) between 2010 and 2020. The study utilized demographic and clinical data, including the Wells score and D-dimer levels, to train a random forest ML model. The model’s effectiveness was assessed using the area under the receiver operating curve (AUROC). In total, 446 patients from hospital A and 139 from hospital B were included. The training set consisted of 356 patients from hospital A, with internal validation on 90 and external validation on 139 patients from hospital B. The model achieved an AUROC of 0.736 in hospital A and 0.669 in hospital B. The ML model significantly reduced the number of patients recommended for CTPA compared to the conventional diagnostic strategy (hospital A; 100.0% vs. 91.1%, P < 0.001, hospital B; 100.0% vs. 93.5%, P = 0.003). The results indicate that an ML-based prediction model can reduce unnecessary CTPA procedures in gastrointestinal cancer patients, highlighting its potential to enhance diagnostic efficiency and reduce patient burden.