BackgroundThere is still a lack of specific indicators to diagnose idiopathic pulmonary fibrosis (IPF). And the role of immune responses in IPF is elusive. In this study, we aimed to identify hub genes for diagnosing IPF and to explore the immune microenvironment in IPF.MethodsWe identified differentially expressed genes (DEGs) between IPF and control lung samples using the GEO database. Combining LASSO regression and SVM-RFE machine learning algorithms, we identified hub genes. Their differential expression were further validated in bleomycin-induced pulmonary fibrosis model mice and a meta-GEO cohort consisting of five merged GEO datasets. Then, we used the hub genes to construct a diagnostic model. All GEO datasets met the inclusion criteria, and verification methods, including ROC curve analysis, calibration curve (CC) analysis, decision curve analysis (DCA) and clinical impact curve (CIC) analysis, were performed to validate the reliability of the model. Through the Cell Type Identification by Estimating Relative Subsets of RNA Transcripts algorithm (CIBERSORT), we analyzed the correlations between infiltrating immune cells and hub genes and the changes in diverse infiltrating immune cells in IPF.ResultsA total of 412 DEGs were identified between IPF and healthy control samples, of which 283 were upregulated and 129 were downregulated. Through machine learning, three hub genes (ASPN, SFRP2, SLCO4A1) were screened. We confirmed their differential expression using pulmonary fibrosis model mice evaluated by qPCR, western blotting and immunofluorescence staining and analysis of the meta-GEO cohort. There was a strong correlation between the expression of the three hub genes and neutrophils. Then, we constructed a diagnostic model for diagnosing IPF. The areas under the curve were 1.000 and 0.962 for the training and validation cohorts, respectively. The analysis of other external validation cohorts, as well as the CC analysis, DCA, and CIC analysis, also demonstrated strong agreement. There was also a significant correlation between IPF and infiltrating immune cells. The frequencies of most infiltrating immune cells involved in activating adaptive immune responses were increased in IPF, and a majority of innate immune cells showed reduced frequencies.ConclusionOur study demonstrated that three hub genes (ASPN, SFRP2,SLCO4A1) were associated with neutrophils, and the model constructed with these genes showed good diagnostic value in IPF. There was a significant correlation between IPF and infiltrating immune cells, indicating the potential role of immune regulation in the pathological process of IPF.