This study is to establish NMF (nonnegative matrix factorization) typing related to the tumor microenvironment (TME) of colorectal cancer (CRC) and to construct a gene model related to prognosis to be able to more accurately estimate the prognosis of CRC patients. NMF algorithm was used to classify samples merged clinical data of differentially expressed genes (DEGs) of TCGA that are related to the TME shared in The Cancer Genome Atlas (TCGA) and Gene Expression Omnibus (GEO) datasets, and survival differences between subtype groups were compared. By using createData Partition command, TCGA database samples were randomly divided into train group and test group. Then the univariate Cox analysis, Lasso regression and multivariate Cox regression models were used to obtain risk model formula, which is used to score the samples in the train group, test group and GEO database, and to divide the samples of each group into high-risk and low-risk groups, according to the median score of the train group. After that, the model was validated. Patients with CRC were divided into 2, 3, 5 subtypes respectively. The comparison of patients with overall survival (OS) and progression-free survival (PFS) showed that the method of typing with the rank set to 5 was the most statistically significant (p=0.007, p<0.001, respectively). Moreover, the model constructed containing 14 immune-related genes (PPARGC1A, CXCL11, PCOLCE2, GABRD, TRAF5, FOXD1, NXPH4, ALPK3, KCNJ11, NPR1, F2RL2, CD36, CCNF, DUSP14) can be used as an independent prognostic factor, which is superior to some previous models in terms of patient prognosis. The 5-type typing of CRC patients and the 14 immune-related genes model constructed by us can accurately estimate the prognosis of patients with CRC.