Introduction: Bronchopulmonary dysplasia (BPD) is a life-threatening lung illness that affects premature infants and has a high incidence and mortality. Using interpretable machine learning, we aimed to investigate the involvement of endoplasmic reticulum (ER) stress-related genes (ERSGs) in BPD patients.Methods: We evaluated the expression profiles of endoplasmic reticulum stress-related genes and immune features in bronchopulmonary dysplasia using the GSE32472 dataset. The endoplasmic reticulum stress-related gene-based molecular clusters and associated immune cell infiltration were studied using 62 bronchopulmonary dysplasia samples. Cluster-specific differentially expressed genes (DEGs) were identified utilizing the WGCNA technique. The optimum machine model was applied after comparing its performance with that of the generalized linear model, the extreme Gradient Boosting, the support vector machine (SVM) model, and the random forest model. Validation of the prediction efficiency was done by the use of a calibration curve, nomogram, decision curve analysis, and an external data set.Results: The bronchopulmonary dysplasia samples were compared to the control samples, and the dysregulated endoplasmic reticulum stress-related genes and activated immunological responses were analyzed. In bronchopulmonary dysplasia, two distinct molecular clusters associated with endoplasmic reticulum stress were identified. The analysis of immune cell infiltration indicated a considerable difference in levels of immunity between the various clusters. As measured by residual and root mean square error, as well as the area under the curve, the support vector machine machine model showed the greatest discriminative capacity. In the end, an support vector machine model integrating five genes was developed, and its performance was shown to be excellent on an external validation dataset. The effectiveness in predicting bronchopulmonary dysplasia subtypes was further established by decision curves, calibration curves, and nomogram analyses.Conclusion: We developed a potential prediction model to assess the risk of endoplasmic reticulum stress subtypes and the clinical outcomes of bronchopulmonary dysplasia patients, and our work comprehensively revealed the complex association between endoplasmic reticulum stress and bronchopulmonary dysplasia.