BackgroundImmune checkpoint inhibitor (ICI)-related pneumonitis (IRP) is a common and potentially fatal clinical adverse event. The identification and prediction of the risk of ICI-related IRP is a major clinical issue. The objective of this study was to apply a machine learning method to explore risk factors and establish a prediction model.MethodsWe retrospectively analyzed 48 patients with IRP (IRP group) and 142 patients without IRP (control group) who were treated with ICIs. An Elastic Net model was constructed using a repeated k-fold cross-validation framework (repeat = 10; k = 3). The prediction models were validated internally and the final prediction model was built on the entire training set using hyperparameters with the best interval validation performance. The generalizability of the final prediction model was assessed by applying it to an independent test set. The overall performance, discrimination, and calibration of the prediction model were evaluated.ResultsEleven predictors were included in the final predictive model: sindillizumab, number of ≥2 underlying diseases, history of lung diseases, tirelizumab, non-small cell lung cancer (NSCLC), percentage of CD4+lymphocytes, body temperature, KPS score ≤70, hemoglobin, cancer stage IV, and history of antitumor therapy. The external validation of the risk prediction model on an independent test set of 37 patients and showed good discrimination and acceptable calibration ability: with AUC of 0.81 (95% CI 0.58–0.90), AP of 0.76, scaled Brier score of 0.31, and Spiegelhalter-z of −0.29 (P-value:0.77). We also designed an online IRP risk calculator for use in clinical practice.ConclusionThe prediction model of ICI-related IRP provides a tool for accurately predicting the occurrence of IRP in patients with cancer who received ICIs.