The Transformer-based model, incorporating 39 variables related to clinical, demographic, metabolic, and nutritional factors, demonstrated strong performance in predicting IC risk. An AUC-ROC of 0.984, accuracy of 95.3%, recall of 94.6%, F1-score of 94.7%, and Brier score of 0.046 are within the range of previously reported performance metrics, although direct comparisons are limited by differences in populations, outcomes, and validation designs, as listed in
Table 1. These results indicate a substantial capacity to detect high-risk patients while maintaining a low false-negative rate, which may be useful for identifying high-risk individuals. A crucial contributor to these outcomes is the inclusion and interaction of specific nutritional parameters, particularly because several other proposals, including those advanced by Wang et al. in (
17) and others such as Buk Cardoso et al. in (
18), rely solely on clinical or hospital information.
In other words, the level of detail in our information directly contributes to improved performance. The Transformer architecture, based on self-attention, can capture non-linear dependencies among variables (age, BMI, experience, diet). This may represent an improvement over standard models (RF, SVM, XGB) because it leverages attention mechanisms.
SHAP-based interpretations were consistent with established epidemiology of IC risk factors; key determinants were vegetable intake (SHAP = -0.0585, a strongly significant protective factor), physical activity (SHAP = -0.0420), processed meat (SHAP = +0.0394), red meat (SHAP = +0.0343), polyps (SHAP = +0.0239), and family history of IC (SHAP = +0.0213). This correspondence between SHAP explanations and epidemiologic relationships increased the interpretability of the findings in relation to the WCRF/AICR (
24). A stability test across 5 distinct runs showed that 84.6% of variables had a coefficient of variation (CV) below 10% for SHAP values. High-impact features showed satisfactory robustness (CV ≤ 6%), suggesting stable interpretability patterns. Waterfall graphs provided representative examples (high risk: 89.6%, low risk: 2.9%) and offered a clear additive view of individual risk calculations, explaining an overall risk of 90.8% resulting from the accumulation of risk factors (for example, daily processed meats +18.2%, presence of polyps +12.6%, regular red meats +10.4%, among others). This strategy has 3 key strengths in the context of WCRF/AICR general risk factor guidelines: risk-level stratification (for high-risk patients > 70% target P
75 and for moderate/low-risk patients target P
50), grounding in reality (targets are set according to the average intake of healthy Moroccans), and achievability (a substantial proportion of the control group has already met the targets). Consequently, a high-risk patient will have more restrictive targets (4 servings/day of vegetables = P
75) than a low-risk patient (2 servings/day = P
50), both based on local evidence. The 2 specific cases presented below demonstrate a personalized adaptation pattern, in which a high-risk patient (90.8%) would follow 7 HIGH-priority recommendations with intensive support (P
75 for vegetables/fruit, 0 red/processed meat), whereas a low-risk patient (3.3%) would receive positive reinforcement without intervention (because their personal habits already meet P
50/P
75 standards). This approach, which has been less frequently investigated in previous studies, may provide a more patient-centered nutritional support strategy.
This study contributes by integrating a personalized nutrition recommendation module based on patient characteristics and key risk factors identified via SHAP. Unlike previous works, our system provides realistic menus that are culturally adapted to the Moroccan context, which, beyond scientific relevance, may enhance practical applicability. This level of contextualization, which is not present in the work of Abdul Rahman et al. (
9), Wu et al. (
16), and Buk Cardoso et al. (
18), represents a potentially useful patient-centered contribution. The developed model may help identify individuals at elevated IC risk in primary care who are considered high risk and therefore require closer monitoring or early colonoscopy. Using SHAP, clinicians can clearly understand why a patient is considered high risk, facilitating doctor–patient communication and potentially improving adherence. An innovative aspect of this project was tailoring the system to the Moroccan environment, including development of a database containing 104 foods with traditional Moroccan names.
The generalizability of the proposed model beyond the Marrakech-Safi region requires careful consideration. The model was trained in a population with specific dietary habits, socioeconomic characteristics, and disease-prevalence patterns that may differ substantially from those of other Moroccan regions, North African populations, or international settings. The food database, comprising 104 traditional Moroccan foods, reflects local dietary patterns and may not be directly applicable to populations with different culinary traditions. External validation in geographically and culturally diverse populations is therefore essential before broader clinical application.
Several limitations should be acknowledged. First, the retrospective case-control design means that the model discriminates between existing cases and controls rather than predicting future cancer incidence, which limits direct clinical application. Second, model evaluation relied exclusively on internal procedures, and external validation in independent cohorts is necessary before any clinical deployment. Third, the study population was drawn only from the Marrakech-Safi region, which may constrain generalizability to other geographic or cultural contexts. Fourth, self-reported dietary and lifestyle data may introduce recall bias and measurement inaccuracies, particularly because recently diagnosed cases may recall past exposures differently than controls. Fifth, some behavioral variables may reflect post-diagnosis changes, introducing a risk of reverse causation. Finally, despite regularization and cross-validation, the combination of a relatively small sample and a high-capacity Transformer architecture carries a residual risk of overfitting. Future work should prioritize external validation, prospective multicenter designs, and longitudinal follow-up before real-world implementation. The current system does not account for individual food allergies or intolerances and does not include specific adaptations for obesity beyond caloric restriction. These are important areas for future development to improve the safety and personalization of the recommendation module.
5.1. Conclusions
This study presents a data-driven approach to IC risk prediction by combining a high-performance Transformer-based risk prediction model, detailed SHAP analysis to support explainability and identify modifiable factors, and an automated approach for providing personalized dietary guidance based on the true health parameters of controls and informed by SHAP values. The proposed model was developed using a cohort of 1 135 samples (493 cases and 642 controls) and 39 clinical, demographic, metabolic, and nutritional variables, providing an integrated approach to address the problem comprehensively. The dataset was split into training (70%), validation (15%), and testing sets to ensure rigorous model appraisal. Test-set results were strong: the model achieved an overall accuracy of 95.3% and an AUC of 0.984. These findings demonstrate favorable performance relative to other models in the recent literature and indicate the capability of the Transformer model to model tabulated data for IC risk prediction. The results showed that SHAP identified dietary variables as major drivers of predicted risk, with vegetable intake (SHAP = –0.0585) and frequency of meat consumption (SHAP = 0.0394) as key driving variables, while stability analysis indicated that results remained stable after 5 iterations, with 84.6% of features having a CV of < 10%. Waterfall plots for 3 cases demonstrated the model’s interpretability for explaining risk to patients.
A key novelty of this work is the implementation of a complete personalized menu-generation system based on a database comprising 104 traditional Moroccan foods, enabling automatic generation of a weekly meal plan. The system is customized to patients’ nutritional needs and culturally adapted to the local context. Whereas most previous studies defined targets using arbitrary thresholds, our system empirically extracts nutritional targets from the actual profile of healthy controls, represented by percentiles P25/P50/P75, to ensure that targets are scientifically sound and locally achievable. Validation across 5 diverse examples showed that the system generally satisfied constraints related to quality (100% achievement of fiber/protein, 77% protective foods, 73.6% variation, 100% cultural accordance).
The recommendations are directly informed by SHAP-based feature contributions, establishing a clear link between the model-identified risk factors and the nutritional recommendations. This study supports the feasibility of smart prevention systems that are culturally adapted and implementable in resource-limited environments, such as Morocco. Future directions include prospective multicenter cohort designs, longitudinal follow-up assessments, and external validation in independent and diverse populations, all of which are required before clinical implementation and may support the development of more individualized and widely accessible nutritional prevention frameworks.