The morbidity rate of ulcerative colitis (UC) in the world is increasing year by year, recurrent episodes of diarrhea, mucopurulent and bloody stools, and abdominal pain are the main symptoms, reducing the quality of life of the patient and affecting the productivity of the society. In this study, we sought to develop robust diagnostic biomarkers for UC, to uncover potential targets for anti-TNF-ɑ drugs, and to investigate their associated pathway mechanisms. We collected single-cell expression profile data from 9 UC or healthy samples and performed cell annotation and cell communication analysis. Revealing the possible pathogenesis of ulcerative colitis by Gene Ontology (GO), Kyoto Encyclopedia of Genes and Genomes (KEGG), and Gene Set Enrichment Analysis (GSEA) analysis. Based on the disease-related modules obtained from weighted correlation network analysis (WGCNA) analysis, we used Lasso regression analysis and random forest algorithm to identify the genes with the greatest impact on disease (EPB41L3, HSD17B3, NDRG1, PDIA5, TRPV3) and further validated the diagnostic value of the model genes by various means. To further explore the relationship and mechanism between model genes and drug sensitivity, we collected gene expression profiles of 185 UC patients before receiving anti-tumor necrosis factor drugs, and we performed functional analysis based on the results of differential analysis between NR tissues and R tissues, and used single-sample GSEA (ssGSEA) and CIBERSORT algorithms to explore the important role of immune microenvironment on drug sensitivity. The results suggest that our model is not only helpful in aiding diagnosis, but also has implications for predicting drug efficacy; in addition, model genes may influence drug sensitivity by affecting immune cells. We suggest that this study has developed a diagnostic model with higher specificity and sensitivity, and also provides suggestions for clinical administration and drug efficacy prediction.