Development and Internal Validation of an Explainable Machine Learning Model for Physical Activity Adherence Among Community-Dwelling Patients with Type 2 Diabetes Mellitus Authors: Yiming Zhao, Mo Zhou, Feng Sun, Chuning Lin, Huimin Niu, Xinyi Zhang, Feng Jiang, Chuyan Wu Published: 2026 ABSTRACT AbstractBackgroundPhysical activity adherence is critical for effective diabetes management, yet non-adherence remains common in community settings. This study sought to construct and internally evaluate an interpretable machine learning model for identifying poor physical activity adherence among patients with Type 2 diabetes mellitus (T2DM) in a community-based setting.MethodsThis single-center cross-sectional study included 207 patients with T2DM receiving community-based care at the Shiqiao Community Health Service Center, China, between January and September 2025. Candidate predictors were selected using Elastic Net regularization followed by multivariable logistic regression. Multiple machine learning algorithms were developed and compared using a randomly allocated training dataset (70%, n = 145) and an internal validation dataset (30%, n = 62). Model discrimination and clinical utility were assessed using the area under the receiver operating characteristic curve (AUC) and decision curve analysis (DCA), respectively. Shapley Additive exPlanations (SHAP) was used to interpret individual predictor contributions to model outputs.ResultsAmong the 207 participants, 113 (54.6%) demonstrated high physical activity adherence. The final model incorporated five key predictors: Summary of Diabetes Self-Care Activities (SDSCA) score, estimated glomerular filtration rate (eGFR_CKD-EPI_2009), family history of diabetes, International Physical Activity Questionnaire (IPAQ) score, and albumin (ALB). The SVM model achieved the highest discrimination ability among the tested algorithms and was subsequently selected as the final model (AUC = 0.787, 95% CI: 0.671–0.903). SHAP analysis provided transparent visualization of the relative contribution of each predictor to model outputs.ConclusionThis study provides an explainable machine learning approach for identifying key variables associated with physical activity adherence among individuals with T2DM in community diabetes management. Further validation in independent populations is needed before the model can be considered for risk assessment and personalized behavioral intervention planning in community diabetes care.Keywords: type 2 diabetes mellitus, physical activity adherence, machine learning, predictive modeling, explainable artificial intelligence, risk stratification Background Diabetes mellitus (DM) represents a major chronic metabolic disease characterized by persistent hyperglycemia, which arises from impaired insulin action, inadequate insulin secretion, or a combination of these abnormalities.1 The growing burden of diabetes represents a substantial challenge for global public health. According to the International Diabetes Federation, approximately 529 million people were living with diabetes worldwide in 2021, and this number is expected to rise to 1.31 billion by 2050.2 In China, the prevalence of diabetes among adults is estimated at 11.9%, whereas the rates of glycemic control, treatment, and disease awareness remain suboptimal at 38.0%, 34.1%, and 33.1%, respectively.3,4 These challenges emphasize the need for practical and sustainable approaches to enhance diabetes management, particularly through strategies that promote long-term lifestyle modification.5,6 Physical activity plays a central role in diabetes management. Regular engagement in physical activity can improve insulin sensitivity and glycemic control while reducing the risk of diabetes-related complications.7,8 Despite its clinical importance, adherence to physical activity prescriptions among individuals with diabetes remains suboptimal. Poor adherence can lead to inadequate glycemic control, worsening metabolic status, and increased risk of long-term complications.9 Therefore, identifying individuals at higher risk of non-adherence could facilitate timely and targeted interventions. Previous research has reported that physical activity adherence in diabetes is influenced by a variety of demographic, psychosocial, and clinical factors, with age, sex, income level, educational attainment, and social support among the factors previously identified.10 In addition, digital health interventions, together with data-driven strategies, are gaining attention as potential means of promoting physical activity and supporting diabetes self-management.11–13 However, existing studies have primarily focused on identifying individual associated factors or evaluating intervention effectiveness, while predictive approaches capable of integrating multidimensional patient characteristics remain limited.14,15 Furthermore, conventional clinical assessments often rely on subjective judgment or isolated indicators, which may not adequately capture the complex interactions among behavioral, clinical, and biological determinants of physical activity adherence. Machine learning (ML) can offer a data-driven pathway that integrates multidimensional behavioral and clinical information for identifying patients with poor recent exercise adherence. ML models such as support vector machines (SVM), logistic regression (LR), and eXtreme Gradient Boosting (XGBoost) have shown superior predictive performance in identifying disease-related risks and optimizing clinical decision-making.16–18 Nevertheless, research applying ML specifically to predict physical activity prescription adherence in people with diabetes remains scarce. Moreover, the lack of interpretability of many ML models has restricted their clinical acceptance.19,20 Explainable artificial intelligence methods, including Shapley additive explanations (SHAP), can enhance model transparency by revealing how individual features influence predictions, thereby facilitating clinical interpretation and risk stratification.21,22 Therefore, we developed an explainable machine learning model to characterize factors associated with recent physical activity adherence among patients with type 2 diabetes mellitus (T2DM) receiving community-based care, with internal validation performed to assess model performance. By integrating behavioral, clinical, and laboratory variables with SHAP-based interpretation, we sought to establish an exploratory risk stratification framework that could provide insights into individualized behavioral intervention strategies and support future diabetes management in community settings. Methods Study Population and Diagnostic Criteria From January 2025 to September 2025, patients with registered chronic disease management records for T2DM at the Public Health Department of the Shiqiao Community Health Service Center were consecutively recruited for this single-center cross-sectional study. A total of 207 participants with complete clinical and questionnaire data were included after undergoing same-day physical examinations and structured questionnaire assessments. Among them, 113 individuals met the criteria for high physical activity adherence. High physical activity adherence was defined according to the Chinese Guidelines for the Prevention and Treatment of Diabetes (2024) and assessed based on self-reported physical activity during the preceding seven days. Participants were classified as having high adherence if they achieved at least 150 minutes of moderate-intensity physical activity per week, with activity distributed across the week according to individual circumstances.23 Therefore, the outcome reflected participants’recent physical activity adherence status at the time of assessment rather than long-term behavioral changes. Inclusion criteria: Eligibility required a diagnosis of type 2 diabetes according to the American Diabetes Association (ADA) criteria and an age of ≥18 years. Exclusion criteria: (1) Type 1 diabetes or gestational diabetes; (2) severe mental illness, cognitive disability, or refusal to participate in the survey; (3) Severe visual, auditory, or speech impairment affecting communication; (4) Severe cardiovascular, hepatic, renal, or musculoskeletal diseases limiting physical activity; (5) Malignant tumors or other life-threatening conditions; (6) Incomplete clinical information or failure to provide informed consent. Ethical approval for this study was granted by the Ethics Committee of the First Affiliated Hospital of Nanjing Medical University (Approval No. 2024-SR-937). Data Collection and Processing The dataset consisted of three major categories of variables, including demographic and clinical characteristics, laboratory indicators, and diabetes-related assessment scales (Table 1). All data were collected during a single assessment window through same-day physical examinations and structured questionnaire assessments. The overall data collection process is illustrated in Figure 1. Table 1Summary of All VariablesVariableAbbreviationDescriptionDemographic and clinical characteristicsAgeAgeYearsSexSexMale/FemaleBody mass indexBMIWeight (kg)/height2 (m2)Waist circumferenceWCcmAnnual incomeIncomeSelf-reported income categoryEducational attainmentEduHighest level of educationFamily history of diabetesFHxYes/NoDiabetes-related complicationsComplicationPresence of diabetic complicationsSmoking and alcohol historySAHYes/NoDiabetes treatment regimenTreatmentOral agents, insulin, or combination therapyExercise supervision statusSUPSupervised/unsupervised exercise programLaboratory indicatorsFasting blood glucoseFBGmmol/LAlbuminALBg/LTotal cholesterolTCmmol/LTriglyceridesTGmmol/LHigh-density lipoprotein cholesterolHDLmmol/LLow-density lipoprotein cholesterolLDLmmol/LSerum creatinineScrμmol/LEstimated glomerular filtration rate (CKD-EPI 2009)eGFR_CKD-EPI_2009Estimated glomerular filtration rate calculated using the 2009 CKD-EPI creatinine equation, unit: mL/min/1.73m2Diabetes-related assessment scalesDiabetes Health Belief ScaleDHBSAssessment of patients’ self-efficacy in diabetes managementInternational Physical Activity Questionnaire – Short FormIPAQAssessment of physical activity intensity and durationAttitudes and Knowledge of Diabetes QuestionnaireADKnowlAssessment of patients’ diabetes-related knowledge and beliefsSummary of Diabetes Self-Care ActivitiesSDSCAMeasures frequency of diabetes self-management behaviorsPatient Assessment of the Impact of DiabetesPAIDEvaluates emotional distress related to diabetesChinese Summary of Diabetes Self-Care Activities – 70 Item ScaleCSSD70Comprehensive assessment of diabetes self-care in Chinese populationDiabetes-Specific Quality of Life ScaleDSQLMeasures diabetes-specific quality of life Summary of All Variables Overview of the study design and machine learning workflow. The flowchart summarizes participant recruitment, data collection, feature selection, model development, evaluation, and model interpretation. A total of 207 community-dwelling patients with type 2 diabetes mellitus were included in the analysis. Candidate variables were screened using Elastic Net regression, followed by backward stepwise multivariable logistic regression to identify final predictors. The dataset was randomly divided into a training set (70%, n = 145) and an internal validation set (30%, n = 62). Multiple machine learning algorithms were developed and compared, with the support vector machine (SVM) model selected as the final predictive model. SHAP analysis was applied for model interpretation, and a web-based application was developed for individualized prediction of physical activity adherence. The number of days of actual physical activity was recorded for each participant. A seven-day assessment window was selected to minimize recall bias and provide a pragmatic assessment of recent physical activity behavior among community-managed patients with T2DM. Physical activity adherence was operationalized as a binary outcome according to guideline-defined criteria, whereas International Physical Activity Questionnaire (IPAQ) and Summary of Diabetes Self-Care Activities (SDSCA) scores were included as behavioral measures reflecting habitual physical activity and diabetes self-management, respectively. No missing data were identified among the included variables; therefore, no imputation procedure was required. Continuous variables were transformed using z-score standardization before machine learning model development. Feature Selection and Model Development A total of 26 candidate variables were considered for feature selection. Elastic Net regression was applied to reduce dimensionality and address potential multicollinearity among candidate predictors. Five-fold cross-validation was performed to identify the optimal lambda value. Predictors with non-zero coefficients under this penalty parameter were retained and further evaluated using a backward stepwise multivariable logistic regression model. Seven variables remained after backward selection, of which five variables with P < 0.1 were retained as the final predictors for machine learning model development.24 The 207 participants were randomly allocated to a training set (70%, n = 145) for model development and an internal validation set (30%, n = 62) for model evaluation. Five machine learning algorithms, including logistic regression (LR), support vector machine (SVM), extreme gradient boosting (XGBoost), random forest (RF), and k-nearest neighbors (KNN), were developed using the selected predictors to classify patients with T2DM according to their recent physical activity adherence status. Model-specific hyperparameters were predefined according to the characteristics of each algorithm, and detailed parameter settings are provided in Table S1. Model Evaluation and Internal Validation Model performance was characterized from multiple perspectives, including discrimination, calibration, and clinical utility. Discriminative ability was quantified using the area under the receiver operating characteristic curve (AUC), sensitivity, specificity, accuracy, F1 score, positive predictive value (PPV), negative predictive value (NPV), and precision-recall (PR) curves. Calibration was examined by comparing predicted probabilities with observed outcomes using calibration curves and Brier scores. Decision curve analysis (DCA) was conducted to estimate the net benefit of each model across different threshold probabilities and to evaluate its potential clinical applicability. After comparing the performance of all candidate algorithms, the SVM approach was chosen for subsequent analyses because of its favorable overall performance. The robustness of the selected model was further examined using ten-fold cross-validation on the entire dataset. Model Explanation SHAP analysis was applied to characterize the influence of individual predictors on model output and provide insights into the decision-making process of the final model. Global SHAP analyses were used to evaluate the relative importance and direction of predictor contributions, whereas individual-level SHAP analyses were used to illustrate how specific features contributed to individual predictions of physical activity adherence status. SHAP analyses and visualizations were performed using Python. Web-Based Model Deployment A Shiny-based web application (version 0.13.2.26) was implemented to provide an accessible interface for applying the developed prediction model. By entering patient characteristics included in the final model, users can obtain estimated probabilities of poor physical activity adherence based on individual profiles. The tool provides a convenient interface for exploring model predictions and may serve as a supportive resource for preliminary risk stratification and future behavioral intervention planning in community diabetes management. Further validation in independent cohorts is necessary to determine whether the model can be generalized to broader clinical settings. Statistical Analysis Statistical analyses were performed in R software (version 4.5.1). Continuous data are reported as medians with interquartile ranges (Q1-Q3), whereas categorical data are expressed as counts and proportions. Univariate logistic regression analyses were performed to evaluate the association of each candidate variable with physical activity adherence status, with high adherence defined as the outcome. Regression findings were summarized using odds ratios (ORs), 95% confidence intervals (CIs), and P values. For categorical variables, the first coded category was used as the reference category. For continuous variables, ORs represent the change in the odds of high physical activity adherence associated with a one-unit increase in the corresponding variable. A two-sided significance threshold of P < 0.05 was applied for all statistical analyses. Results Baseline Characteristics of Participants The study population consisted of 207 patients with T2DM recruited from the Shiqiao Community Health Service Center. Among them, 113 patients (54.6%) met the predefined criteria for high physical activity adherence, while 94 (45.4%) were classified as having low adherence. The 207 participants were randomly assigned to training (n = 145) and internal validation (n = 62) sets for model development and assessment. Descriptive characteristics and univariate logistic regression analyses of the candidate variables according to physical activity adherence status are presented in Table 2. No significant differences were observed between adherence groups regarding demographic and clinical variables, including age, sex, BMI, waist circumference, annual income, educational attainment, family history of diabetes, smoking and alcohol status, number of complications, and treatment regimen (all P > 0.05). Table 2Candidate Predictors and Univariate Logistic Regression Analysis According to Physical Activity Adherence StatusVariableLow Adherence (n = 94)High Adherence (n = 113)OR (95% CI)P valueAge, years69.00 [63.00, 72.00]69.00 [64.00, 73.00]1.011 (0.968–1.055)0.620Sex, n (%)Female58 (61.7)56 (49.6)Reference—Male36 (38.3)57 (50.4)1.640 (0.941–2.859)0.081BMI, kg/m225.38 [23.25, 27.05]25.19 [23.34, 26.78]0.987 (0.910–1.070)0.749WC, cm88.00 [81.25, 94.00]88.00 [83.00, 93.00]0.998 (0.969–1.028)0.896Annual income, CNY, n (%)≤800064 (68.1)75 (66.4)Reference—8001–20,00017 (18.1)10 (8.8)0.502 (0.215–1.174)0.11220,001–100,00013 (13.8)28 (24.8)1.838 (0.879–3.843)0.106Educational attainment, n (%)College or above1 (1.1)1 (0.9)Reference—High school/vocational school6 (6.4)12 (10.6)2.000 (0.106–37.830)0.644Junior high school18 (19.1)21 (18.6)1.167 (0.068–20.017)0.915Primary school26 (27.7)31 (27.4)1.192 (0.071–20.012)0.903Illiterate43 (45.7)48 (42.5)1.116 (0.068–18.398)0.939Family history of diabetes, n (%)No61 (64.9)66 (58.4)Reference—Yes33 (35.1)47 (41.6)1.316 (0.748–2.316)0.340Number of complications, n (%)No complications59 (62.8)72 (63.7)Reference—One complication29 (30.9)32 (28.3)0.904 (0.492–1.663)0.746Two or more complications6 (6.4)9 (8.0)1.229 (0.414–3.652)0.710Smoking and alcohol status, n (%)Neither smoking nor drinking66 (70.2)77 (68.1)Reference—Smoking only9 (9.6)12 (10.6)1.143 (0.453–2.881)0.777Drinking only8 (8.5)10 (8.8)1.071 (0.400–2.872)0.891Smoking and drinking11 (11.7)14 (12.4)1.091 (0.464–2.566)0.842Diabetes treatment regimen, n (%)No pharmacological treatment35 (37.2)40 (35.4)Reference—Monotherapy46 (48.9)64 (56.6)1.217 (0.674–2.198)0.514Combination therapy13 (13.8)9 (8.0)0.606 (0.231–1.587)0.308Exercise supervision status, n (%)No supervision40 (42.6)47 (41.6)Reference—Family supervision40 (42.6)38 (33.6)0.809 (0.438–1.491)0.496Professional supervision12 (12.8)17 (15.0)1.206 (0.515–2.823)0.667Family and professional supervision2 (2.1)11 (9.7)4.681 (0.979–22.376)0.053DHBS88.00 [83.00, 92.00]89.00 [85.00, 92.00]1.036 (0.989–1.085)0.137IPAQ, n (%)Low36 (38.3)17 (15.0)Reference—Moderate34 (36.2)58 (51.3)3.612 (1.766–7.388)<0.001High24 (25.5)38 (33.6)3.353 (1.552–7.246)0.002ADKnowl53.50 [47.00, 61.00]57.00 [50.00, 63.00]1.021 (0.996–1.046)0.097SDSCA25.00 [18.00, 32.00]38.00 [27.00, 44.00]1.072 (1.044–1.101)<0.001PAID10.00 [2.50, 18.44]11.25 [2.50, 21.25]1.012 (0.989–1.036)0.302CSSD7029.50 [24.12, 34.00]30.00 [26.00, 36.00]1.028 (0.991–1.065)0.137DSQL53.00 [44.00, 62.75]51.00 [45.00, 58.00]0.997 (0.974–1.020)0.803FBG, mmol/L7.44 [6.31, 8.62]7.13 [6.05, 8.56]0.968 (0.860–1.089)0.588ALB, g/L46.00 [44.00, 47.00]46.00 [44.00, 47.00]1.035 (0.943–1.137)0.467TC, mmol/L4.88 [3.97, 5.91]4.79 [4.19, 5.35]0.875 (0.700–1.094)0.241TG, mmol/L1.27 [0.98, 1.93]1.46 [1.01, 1.91]1.124 (0.889–1.422)0.329HDL, mmol/L1.32 [1.14, 1.55]1.28 [1.07, 1.50]0.684 (0.346–1.351)0.274LDL, mmol/L2.85 [2.04, 3.65]2.65 [2.05, 3.13]0.771 (0.573–1.037)0.086Scr, μmol/L65.70 [54.00, 76.75]72.00 [58.50, 93.20]1.013 (1.001–1.025)0.033eGFR_CKD-EPI_2009, mL/min/1.73 m290.06 [76.45, 96.16]85.77 [69.24, 93.35]0.981 (0.965–0.997)0.018Notes: Data are presented as median [Q1, Q3] or n (%), as appropriate. Odds ratios (ORs), 95% confidence intervals (CIs), and P values were derived from univariate logistic regression analyses with high physical activity adherence as the outcome. For categorical variables, the first listed category was used as the reference category. For continuous variables, ORs represent the change in odds of high physical activity adherence associated with a one-unit increase in the corresponding variable.Abbreviations: Q1, first quartile; Q3, third quartile; OR, odds ratio; CI, confidence interval; BMI, body mass index; WC, waist circumference; DHBS, Diabetes Health Belief Scale; IPAQ, International Physical Activity Questionnaire; ADKnowl, Audit of Diabetes Knowledge; SDSCA, Summary of Diabetes Self-Care Activities; PAID, Problem Areas in Diabetes; CSSD70, Control Status Scale for Diabetes; DSQL, Diabetes Specific Quality of Life; FBG, fasting blood glucose; ALB, albumin; TC, total cholesterol; TG, triglycerides; HDL, high-density lipoprotein cholesterol; LDL, low-density lipoprotein cholesterol; Scr, serum creatinine; eGFR, estimated glomerular filtration rate; CKD-EPI, Chronic Kidney Disease Epidemiology Collaboration. Candidate Predictors and Univariate Logistic Regression Analysis According to Physical Activity Adherence Status Notes: Data are presented as median [Q1, Q3] or n (%), as appropriate. Odds ratios (ORs), 95% confidence intervals (CIs), and P values were derived from univariate logistic regression analyses with high physical activity adherence as the outcome. For categorical variables, the first listed category was used as the reference category. For continuous variables, ORs represent the change in odds of high physical activity adherence associated with a one-unit increase in the corresponding variable. Abbreviations: Q1, first quartile; Q3, third quartile; OR, odds ratio; CI, confidence interval; BMI, body mass index; WC, waist circumference; DHBS, Diabetes Health Belief Scale; IPAQ, International Physical Activity Questionnaire; ADKnowl, Audit of Diabetes Knowledge; SDSCA, Summary of Diabetes Self-Care Activities; PAID, Problem Areas in Diabetes; CSSD70, Control Status Scale for Diabetes; DSQL, Diabetes Specific Quality of Life; FBG, fasting blood glucose; ALB, albumin; TC, total cholesterol; TG, triglycerides; HDL, high-density lipoprotein cholesterol; LDL, low-density lipoprotein cholesterol; Scr, serum creatinine; eGFR, estimated glomerular filtration rate; CKD-EPI, Chronic Kidney Disease Epidemiology Collaboration. Among the behavioral and laboratory variables, higher SDSCA scores were associated with greater odds of high physical activity adherence (OR = 1.072, 95% CI: 1.044–1.101; P < 0.001). Compared with participants with low IPAQ levels, those with moderate (OR = 3.612, 95% CI: 1.766–7.388; P < 0.001) and high IPAQ levels (OR = 3.353, 95% CI: 1.552–7.246; P = 0.002) had greater odds of high physical activity adherence. Similarly, higher serum creatinine levels were associated with increased odds of high physical activity adherence (OR = 1.013, 95% CI: 1.001–1.025; P = 0.033), whereas higher eGFR_CKD-EPI_2009 values were associated with decreased odds of high physical activity adherence (OR = 0.981, 95% CI: 0.965–0.997; P = 0.018). Feature Selection for Model Development Elastic Net regression was applied to identify relevant predictors, with physical activity adherence status specified as the outcome and candidate variables entered as input features (Figure 2). Elastic Net regularization incorporates characteristics of both ridge regression and least absolute shrinkage and selection operator (LASSO) regression through combined L1 and L2 penalties, allowing selection of informative variables while controlling model complexity.25 The regularization parameter was optimized through five-fold cross-validation. Feature selection using Elastic Net regression. (A) Coefficient trajectories of candidate variables across different lambda values. (B) Cross-validation results for selecting the optimal regularization parameter. The optimal lambda.min and lambda.1se values are indicated by vertical dashed lines. Using this approach, the initial 26 candidate variables were reduced to nine potential predictors: SDSCA, IPAQ, eGFR_CKD-EPI_2009, albumin (ALB), family history of diabetes (FHx), Diabetes Health Belief Scale (DHBS), low-density lipoprotein cholesterol (LDL), exercise supervision status (SUP), and sex (SEX). The nine candidate variables identified by Elastic Net were subsequently assessed in a backward stepwise multivariable logistic regression model. Following stepwise selection, seven variables were retained in the final regression model (Table S2). Among these variables, those meeting the predefined significance criterion of P < 0.1 were selected for machine learning model development, resulting in five final predictors: SDSCA, IPAQ, eGFR_CKD-EPI_2009, ALB, and FHx. Multi-Model Comparison and Selection of the Final Model Performance was compared across five algorithms: XGBoost, LR, RF, SVM, and KNN. SVM yielded the largest AUC in both data partitions, with values of 0.872 in the training set and 0.787 (95% CI: 0.671–0.903) in the internal validation set (Figure 3A–C and Table S3). Comparison of machine learning model performance. (A–C) Receiver operating characteristic (ROC) curves of five machine learning models in the training dataset, validation dataset, and overall dataset. (D) Decision curve analysis (DCA) evaluating the net benefit of the models across different threshold probabilities in the validation dataset. (E) Calibration curves assessing agreement between predicted and observed probabilities. (F) Precision-recall curves of the evaluated models in the validation dataset. Abbreviations: LR, logistic regression; RF, random forest; SVM, support vector machine; XGB, extreme gradient boosting; KNN, k-nearest neighbors; AUC, area under the curve; AP, average precision. To further evaluate model performance, calibration analysis, DCA, and PR curve analyses were performed. Decision curve analysis indicated that SVM provided a higher net benefit than the alternative models over the evaluated range of threshold probabilities (Figure 3D). Calibration curves showed comparable calibration performance among the five models, with Brier scores summarized in Table S4; Nevertheless, the interpretation of these results should take into account the relatively small sample size of the study (Figure 3E). PR curve analysis further demonstrated comparable precision-recall performance among the evaluated models in the internal validation dataset (Figure 3F and Table S4). Considering its overall performance across discrimination, calibration, and decision analyses, SVM was retained for subsequent evaluation. Final Model Development and Internal Validation The selected SVM model was subsequently examined through ten-fold cross-validation performed on the entire dataset to evaluate its performance consistency. Across the ten folds, the mean AUC was 0.859 ± 0.014 for the training folds and 0.724 ± 0.111 for the corresponding testing folds (Figure 4A and B; Table S5). The fold-specific AUC values showed some variability, particularly among the testing folds, reflecting the potential influence of the limited sample size on model performance. Ten-fold cross-validation assessment of the final SVM model. (A) ROC curves of training folds across ten-fold cross-validation. (B) ROC curves of testing folds across ten-fold cross-validation. Mean AUC values across folds are shown in the legends to demonstrate model stability. The lower discrimination performance observed in testing folds compared with training folds suggested a potential degree of overfitting, which is a common challenge for machine learning models developed from relatively small datasets. Nevertheless, the SVM model maintained acceptable discrimination performance during internal validation. Validation using larger external cohorts will be necessary to determine whether the model can be generalized to broader populations. Model Explanation SHAP-based interpretation was used to explore the relationship between individual predictors and the output of the final SVM model, providing insights into how each variable affected the predicted probability of high physical activity adherence.26 As shown in Figure 5A, the five most influential predictors contributing to the model output were identified. Each horizontal line represents SHAP values for individual participants, and the color gradient indicates the magnitude of predictor values, ranging from higher (red) to lower (blue) values. Higher SDSCA and IPAQ scores contributed to increased model-predicted adherence probability, whereas lower values contributed to reduced probability. eGFR_CKD-EPI_2009 showed a negative contribution pattern in the SHAP analysis, with higher values generally contributing to lower model-predicted adherence probability. In addition, the presence of a family history of diabetes (FHx=1) contributed positively to model predictions, whereas lower albumin levels showed negative contributions to the predicted adherence probability. Interpretation of the SVM model using SHAP analysis. (A) SHAP summary plot showing the magnitude and direction of predictor contributions. Each point represents an individual observation, with colour indicating feature values. (B) Global feature importance ranked by mean absolute SHAP values. (C and D) SHAP waterfall plots illustrating individual prediction explanations and the contribution of each predictor to model output. Abbreviations: SHAP, Shapley additive explanations; SDSCA, Summary of Diabetes Self-Care Activities; IPAQ, International Physical Activity Questionnaire; eGFR_CKD-EPI_2009, estimated glomerular filtration rate calculated using the CKD-EPI equation; ALB, albumin; FHx, family history of diabetes. In Figure 5B, predictors were ordered according to their mean absolute SHAP values, reflecting their relative contributions to the SVM model output. SDSCA, IPAQ, eGFR_CKD-EPI_2009, FHx, and ALB showed the greatest contributions to model output. Figures 5C and D illustrate two representative patients with different model-predicted probabilities (0.62 and 0.38), demonstrating how individual characteristics contributed to personalized model interpretation. Interactive Web-Based Prediction Tool The final SVM model was implemented as an R-based web application. Using the five selected predictors (SDSCA, IPAQ, eGFR_CKD-EPI_2009, ALB, and FHx), the tool generates individualized probabilities of recent physical activity adherence among patients with type 2 diabetes mellitus (Figure 6). The application was designed to facilitate model interpretation and exploratory risk stratification. The deployed application is available online at: https://akafeimifeng.shinyapps.io/svm_predictor/. Conceptual framework of the explainable machine learning approach for physical activity adherence assessment in patients with type 2 diabetes mellitus. The framework integrates multidomain predictors with an explainable SVM model and SHAP analysis to support exploratory risk stratification. Discussion This community-based study enrolled 207 patients with T2DM and revealed that 45.41% of participants did not meet the predefined threshold for high physical activity adherence, highlighting that suboptimal adherence remains a common and clinically relevant issue in primary care populations.27 Despite extensive evidence supporting the benefits of regular exercise for glycemic control, cardiovascular protection, and overall metabolic health, identifying individuals at risk of poor adherence in community-based diabetes care remains challenging.28 Current approaches often rely on routine clinical assessment and behavioral evaluation, which may lack systematic quantitative methods to support individualized risk stratification.29 Therefore, developing interpretable tools that can identify patients with lower recent physical activity adherence may provide additional information for future targeted behavioral support strategies. To address this gap, our study employed machine learning techniques to develop an exploratory cross-sectional framework for identifying recent physical activity adherence status by integrating behavioral, clinical, and laboratory variables.30 Compared with the other algorithms, SVM achieved the highest AUC in the initial internal validation (AUC = 0.787) and provided greater net benefit across the assessed threshold probability range. Nevertheless, the observed variability in discrimination performance and the reduced predictive ability during cross-validation suggest that this model should currently be considered an exploratory tool for risk stratification rather than a validated clinical decision-support system. The final model incorporated five readily obtainable predictors: SDSCA score, eGFR_CKD-EPI_2009, FHx, IPAQ score, and ALB level. Together, these variables reflected multiple dimensions associated with physical activity adherence status, highlighting the potential of interpretable machine learning approaches to capture complex relationships among behavioral and clinical characteristics beyond conventional approaches based on individual predictors. This study provides several methodological contributions. First, it explores a data-driven approach to support risk stratification of physical activity adherence status in community-based diabetes management. Evidence regarding the use of explainable machine learning approaches for predicting recent physical activity adherence among community-based individuals with diabetes remains limited. By integrating behavioral, clinical, and laboratory variables, this framework provides a structured quantitative approach for identifying individuals who may be at higher risk of suboptimal adherence. Second, the incorporation of SHAP analysis improves model interpretability and transparency, addressing an important challenge in the application of machine learning approaches in clinical research.31 SHAP visualizations illustrate the relative contribution of individual predictors to model outputs at both global and individual levels, providing insights into how different characteristics influence model classification. Third, this study highlights the potential value of integrating behavioral and clinical characteristics rather than relying solely on physiological indicators. Such a multidimensional framework may contribute to future research on personalized behavioral management strategies in diabetes care. Among the predictors, SDSCA emerged as the most influential variable, highlighting that physical activity adherence may be closely linked to broader self-management behaviors rather than representing an isolated behavior.32 Higher SDSCA scores may reflect greater engagement in diabetes self-management activities, which could be associated with more consistent adoption of healthy behaviors, including regular physical activity.33 The inclusion of eGFR and ALB in the model suggests that physiological and nutritional characteristics may contribute to the identification of individuals with different physical activity adherence status.34 Reduced renal function may be accompanied by decreased physical capacity, fatigue, and functional limitations, while lower albumin levels may reflect poorer nutritional status or underlying disease burden, potentially influencing participation in physical activity.35 However, these associations should be interpreted cautiously, as the current cross-sectional study cannot establish causal relationships. Further longitudinal studies are needed to clarify the mechanisms linking physiological status and long-term exercise behavior. Interestingly, the contributions of FHx and IPAQ suggest the complexity of behavioral characteristics associated with physical activity adherence status. A positive family history of diabetes was associated with variation in adherence patterns in the current model. This association may reflect differences in disease awareness, perceived health risks, or behavioral adaptation among individuals with hereditary risk; however, the underlying mechanisms require further investigation using dedicated psychological and behavioral assessments.36 Similarly, although lower IPAQ scores may indicate reduced habitual physical activity and a higher likelihood of suboptimal adherence status, higher IPAQ scores should also be interpreted cautiously. Self-reported activity measures may not fully reflect the quantitative and contextual characteristics of exercise behaviors, and discrepancies between perceived and objectively measured physical activity may exist.37,38 These findings highlight the importance of interpreting quantitative activity measures together with complementary behavioral assessments and objective activity measurements. Certain variables that showed associations in preliminary analyses, such as DHBS, were not retained as final predictors after multivariable screening and machine learning model development. Their information may overlap with other behavioral indicators, such as SDSCA, or may provide limited additional contribution after considering multiple correlated characteristics simultaneously. This finding highlights the potential utility of integrative modeling approaches in handling complex variable relationships and identifying informative features within multidimensional clinical datasets. The proposed SVM-based model demonstrates potential relevance as an exploratory risk-stratification tool in community-based diabetes management. The use of routinely collected behavioral and clinical variables may improve the feasibility of future application in primary care settings, although integration into electronic health records and clinical workflows requires further evaluation. By providing interpretable estimates of recent physical activity adherence status, the model may offer additional information for identifying individuals who could benefit from further behavioral assessment or support. The accompanying web-based application enhances accessibility and allows users to visualize model outputs in real time,39 providing a convenient platform for exploratory assessment and future model refinement. Nevertheless, several limitations should be acknowledged. First, the applicability of our findings to other populations may be constrained by the single-center design and limited sample size. External validation in larger, multicenter independent cohorts is required to evaluate the robustness and transportability of the proposed framework. Second, the present model was developed using cross-sectional data and therefore identifies current physical activity adherence status rather than predicting future behavioral changes. As physical activity behavior may fluctuate over time, the current framework cannot fully capture long-term adherence trajectories. In addition, important behavioral, psychosocial, and clinical factors, such as health beliefs, depression, medication adherence, social support, and comorbidity burden, were not comprehensively assessed and should be considered in future studies. Furthermore, both predictors and outcomes were collected within a short and closely aligned assessment window, indicating that the model primarily reflects recent exercise behavior status. Therefore, the observed performance should be interpreted as reflecting short-term behavioral classification rather than long-term adherence prediction. Future studies should incorporate longitudinal designs with repeated assessments and objective physical activity measurements, such as wearable-derived activity indicators, to evaluate behavioral transitions over time and improve the robustness and generalizability of future models. Conclusions We established and internally evaluated an explainable SVM-based machine learning framework to identify recent physical activity adherence status among individuals with T2DM in community settings. The model incorporated five key predictors, including SDSCA, IPAQ, eGFR_CKD-EPI_2009, ALB, and FHx, demonstrating the potential value of integrating behavioral, clinical, and laboratory characteristics for exploratory risk stratification in diabetes management. Given that the model was developed from a small single-center cohort with internal validation only, it should be considered a methodological framework rather than a clinically validated decision-support tool. Further studies involving multicenter external validation, longitudinal assessment, and objective physical activity measurements are required before broader clinical application. Funding Statement This work was supported by the Clinical Capacity Enhancement Project of Jiangsu Province Hospital, the First Affiliated Hospital with Nanjing Medical University (Grant No. JSPH-MC-2022-19). The funders had no role in the study design, data collection, analysis, interpretation, or manuscript preparation. Data Sharing Statement The datasets generated and analysed during the current study are available from the corresponding author, Chuyan Wu, upon reasonable request. The web-based prediction tool was developed using the Shiny framework and can be accessed upon request for academic or clinical use. Statement of Ethics This study was conducted in accordance with the Declaration of Helsinki. Ethical approval was obtained from the Ethics Committee of the First Affiliated Hospital of Nanjing Medical University (Approval No. 2024-SR-937). All participants were informed of the purpose and procedures of the study and provided written informed consent. Author Contributions All authors made a significant contribution to the work reported, whether that is in the conception, study design, execution, acquisition of data, analysis and interpretation, or in all these areas; took part in drafting, revising or critically reviewing the article; gave final approval of the version to be published; have agreed on the journal to which the article has been submitted; and agree to be accountable for all aspects of the work. Disclosure It has been confirmed by the authors that there are no conflicts of interest. References Associated Data Data Availability Statement The datasets generated and analysed during the current study are available from the corresponding author, Chuyan Wu, upon reasonable request. The web-based prediction tool was developed using the Shiny framework and can be accessed upon request for academic or clinical use.