The gut microbiota plays an important role in the regulation of the immune system and the metabolism of the host. The aim of the present study was to characterize the gut microbiota of patients with type 2 diabetes mellitus (T2DM). A total of 118 participants with newly diagnosed T2DM and 89 control subjects were recruited in the present study; six clinical parameters were collected and the quantity of 10 different types of bacteria was assessed in the fecal samples using quantitative PCR. Taking into consideration the six clinical variables and the quantity of the 10 different bacteria, 3 predictive models were established in the training set and test set, and evaluated using a confusion matrix, area under the receiver operating characteristic curve (AUC) values, sensitivity (recall), specificity, accuracy, positive predictive value and negative predictive value (npv). The abundance of Bacteroides, Eubacterium rectale and Roseburia inulinivorans was significantly lower in the T2DM group compared with the control group. However, the abundance of Enterococcus was significantly higher in the T2DM group compared with the control group. In addition, Faecalibacterium prausnitzii, Enterococcus and Roseburia inulinivorans were significantly associated with sex status while Bacteroides, Bifidobacterium, Enterococcus and Roseburia inulinivorans were significantly associated with older age. In the training set, among the three models, support vector machine (SVM) and XGboost models obtained AUC values of 0.72 and 0.70, respectively. In the test set, only SVM obtained an AUC value of 0.77, and the precision and specificity were both above 0.77, whereas the accuracy, recall and npv were above 0.60. Furthermore, Bifidobacterium, age and Roseburia inulinivorans played pivotal roles in the model. In conclusion, the SVM model exhibited the highest overall predictive power, thus the combined use of machine learning tools with gut microbiome profiling may be a promising approach for improving early prediction of T2DM in the near feature.