Diabetic ketoacidosis (DKA) is a frequent acute complication of diabetes mellitus (DM). It develops quickly, produces severe symptoms, and greatly affects the lives and health of individuals with DM.This article utilizes machine learning methods to examine the baseline characteristics that significantly contribute to the development of DKA. Its goal is to identify and prevent DKA in a targeted and early manner. This study selected 2382 eligible diabetic patients from the MIMIC-IV dataset, including 1193 DM patients with ketoacidosis and 1186 DM patients without ketoacidosis. A total of 42 baseline characteristics were included in this research. The research process was as follows: Firstly, important features were selected through Pearson correlation analysis and random forest to identify the relevant physiological indicators associated with DKA. Next, logistic regression was used to individually predict DKA based on the 42 baseline characteristics, analyzing the impact of different physiological indicators on the experimental results. Finally, the prediction of ketoacidosis was performed by combining feature selection with machine learning models include logistic regression, XGBoost, decision tree, random forest, support vector machine, and k-nearest neighbors classifier. Based on the importance analysis conducted using different feature selection methods, the top five features in terms of importance were identified as mean hematocrit (haematocrit_mean), mean hemoglobin (haemoglobin_mean), mean anion gap (aniongap_mean), age, and Charlson comorbidity index (charlson_comorbidity_index). These features were found to have significant relevance in predicting DKA. In the individual prediction using logistic regression, these five features have been proven to be effective, with F1 scores of 1.000 for hematocrit mean, 0.978 for haemoglobin_mean, 0.747 for age, 0.692 for aniongap_mean and 0.666 for charlson_comorbidity_index. These F1 scores indicate the effectiveness of each feature in predicting DKA, with the highest score achieved by mean hematocrit. In the prediction of DKA using machine learning models, including logistic regression, XGBoost, decision tree, and random forest demonstrated excellent results, achieving an F1 score of 1.000. Additionally, by applying feature selection techniques, noticeable improvements were observed in the experimental performance of the support vector machine and k-nearest neighbors classifier. The study found that hematocrit, hemoglobin, anion gap, age, and Charlson comorbidity index are closely associated with ketoacidosis. In clinical practice, these five baseline characteristics should be given with the special attention to achieve early detection and treatment, thus reducing the incidence of the disease.