High-risk human papillomavirus (HR-HPV) is a significant risk factor for cervical precancerous lesions and cancer. This study aimed to investigate the relationship between vaginal microecology and HR-HPV infection and to evaluate the clinical applicability of vaginal microecology in predicting HR-HPV infection. Overall, 2000 women with simultaneously detected vaginal discharge and cervical HPV were selected between March 2022 and March 2023, including 241 and 1759 cases in the HR-HPV positive and HPV negative groups, respectively. No significant differences were found in age, vulvovaginal candidiasis, trichomonas vaginitis, and β-N-acetylglucosaminosidase between the two groups (P>0.05). Significant differences were observed in Lactobacillus deficiency, bacterial vaginitis (BV), aerobic vaginitis (AV), glucuronidase (GUS), sialidase (SNA), and leukocyte esterase (LE) between the two groups (P<0.05). In the multivariate logistic regression equation, Lactobacillus deficiency, BV, AV, SNA, LE, and GUS were risk factors for HR-HPV infection (P<0.05). Three prediction models, namely, logistic regression, decision tree, and random forest, were established to rank the importance of the predictors. BV ranked first among the three prediction models. The logistic regression model demonstrated the highest accuracy in predicting the risk of HR-HPV infection. The calibration curve of the logistic regression model showed a strong correlation between the predicted and actual probabilities, and decision curve analysis revealed that the prediction model had good clinical applicability. Overall, vaginal microecology imbalance was closely associated with cervical HR-HPV infection, particularly BV and AV. The logistic regression model for the risk of HR-HPV infection based on six predictive factors (BV, AV, LE, SNA, Lactobacillus deficiency, and GUS) had good accuracy and clinical applicability.