Objective To explore the independent risk factors for hospital infections in tertiary hospitals in Gansu Province, and establish and validate a prediction model. Methods A total of 690 patients hospitalized with hospital infections in Gansu Provincial Hospital between January and December 2021 were selected as the infection group; matched with admission department and age at a 1∶1 ratio, 690 patients who were hospitalized during the same period without hospital infections were selected as the control group. The information including underlying diseases, endoscopic operations, blood transfusion and immunosuppressant use of the two groups were compared, the factors influencing hospital infections in hospitalized patients were analyzed through multiple logistic regression, and the logistic prediction model was established. Eighty percent of the data from Gansu Provincial Hospital were used as the training set of the model, and the remaining 20% were used as the test set for internal validation. Case data from other three hospitals in Gansu Province were used for external validation. Sensitivity, specificity, accuracy, and area under the receiver operating characteristic curve (AUC) were used to evaluate the model effectiveness. Results Multiple logistic regression analysis showed that endoscopic therapeutic manipulation [odds ratio (OR)=3.360, 95% confidence interval (CI) (2.496, 4.523)], indwelling catheter [OR=3.100, 95%CI (2.352, 4.085)], organ transplantation/artifact implantation [OR=3.133, 95%CI (1.780, 5.516)], blood or blood product transfusions [OR=3.412, 95%CI (2.626, 4.434)], glucocorticoids [OR=2.253, 95%CI (1.608, 3.157)], the number of underlying diseases [OR=1.197, 95%CI (1.068, 1.342)], and the number of surgical procedures performed during hospitalization [OR=1.221, 95%CI (1.096, 1.361)] were risk factors for hospital infections. The regression equation of the prediction model was: logit(P)=–2.208+1.212×endoscopic therapeutic operations+1.131×indwelling urinary catheters+1.142×organ transplantation/artifact implantation+1.227×transfusion of blood or blood products+0.812×glucocorticosteroids+0.180×number of underlying diseases+0.200×number of surgical procedures performed during the hospitalization. The internal validation set model had a sensitivity of 72.857%, a specificity of 77.206%, an accuracy of 76.692%, and an AUC value of 0.817. The external validation model had a sensitivity of 63.705%, a specificity of 70.934%, an accuracy of 68.669%, and an AUC value of 0.726. Conclusions Endoscopic treatment operation, indwelling catheter, organ transplantation/artifact implantation, blood or blood product transfusion, glucocorticoid, number of underlying diseases, and number of surgical cases during hospitalization are influencing factors of hospital infections. The model can effectively predict the occurrence of hospital infections and guide the clinic to take preventive measures to reduce the occurrence of hospital infections.