Application of machine learning algorithms and SHAP explanations to predict fertility preference among reproductive women in Somalia

Wait 5 sec.

BackgroundFertility preferences, which encompass the desire for additional children or the decision to cease childbearing, are critical indicators of reproductive intentions and population dynamics1,2. These preferences play a pivotal role in shaping fertility rates and are integral to achieving global reproductive health and population goals, including those outlined in the Sustainable Development Goals (SDGs)3,4. Understanding the determinants of fertility preferences is essential for designing effective interventions that address unmet needs for family planning, promote maternal and child health, and support gender equity in reproductive decision-making5,6.While substantial research has explored fertility preferences using conventional statistical methods, there remains a significant gap in the application of advanced machine learning techniques to predict fertility preferences, particularly in low-resource settings such as Somalia. Traditional models, such as logistic regression, often assume linearity and may oversimplify the complex interactions between sociodemographic and geographic factors influencing fertility decisions. Previous studies have predominantly focused on individual demographic and socioeconomic determinants using these methods, which, while useful, often fail to capture complex, nonlinear relationships and interactions between multiple predictors7,8. Moreover, most research on machine learning applications in fertility prediction has centered on male fertility, with relatively little focus on women’s fertility preferences9,10,11,12. The role of artificial intelligence (AI) in assessing human fertility using risk factors has been extensively reviewed, highlighting the importance of data augmentation, explainability, and feature extraction in predictive models10. However, the majority of AI applications in fertility research have focused on infertility diagnosis rather than fertility preferences, particularly among women, creating a gap that this study seeks to address. Recent reviews have highlighted the application of interpretable machine learning methods in healthcare, including SHAP-based approaches for clinical decision-making13,14. The emergence of Explainable AI techniques, such as Shapley Additive Explanations (SHAP), presents an opportunity to enhance model interpretability, providing transparent and actionable insights into key predictors of fertility preferences11,15,16. Despite the increasing adoption of machine learning in healthcare and demographic research, studies that leverage Explainable AI methods to analyze fertility preferences among women remain scarce. This study aims to bridge these gaps by integrating machine learning and SHAP analysis to predict fertility preferences among reproductive-aged women in Somalia, offering a novel approach to understanding reproductive health behaviors in a high-fertility, low-resource setting.This study makes several key contributions to the existing literature. First, it applies state-of-the-art machine learning algorithms to analyze fertility preferences among women in Somalia, a context characterized by high fertility rates, limited access to reproductive health services, and complex socio-cultural determinants of childbearing decisions5,17. Among these factors, access to healthcare services plays a crucial role in shaping fertility preferences. In many low-resource settings, including Somalia, long distances to health facilities have been identified as a significant barrier to maternal and reproductive healthcare, influencing both contraceptive use and fertility decisions18,19. Limited access to healthcare often results in lower uptake of family planning services, higher fertility rates, and increased unmet need for contraception, particularly in rural and nomadic populations where physical and financial constraints exacerbate the problem17,20,21.Furthermore, the perception of healthcare accessibility influences reproductive decision-making, as women who struggle to reach health facilities may be less likely to seek antenatal care, leading to higher fertility preferences driven by concerns over maternal and child survival22,23. However, existing literature primarily views distance as a barrier to service utilization, but its potential role as a determinant of reproductive intentions remains underexplored1,24,25,26. It is possible that women with better access to health facilities may develop different fertility preferences, potentially due to increased confidence in maternal healthcare and child survival27,28. Given the critical role of healthcare accessibility in shaping reproductive behaviours, further investigation into this perspective is warranted29. However, traditional statistical methods may not effectively capture these complex relationships. Machine learning provides a novel approach by uncovering hidden patterns and interactions in large datasets that may not be evident using conventional techniques. This study provides empirical insights into the role of healthcare access in fertility preferences by leveraging machine learning techniques to analyze the relationship between distance to health facilities and reproductive intentions.By comparing multiple machine learning models, this study identifies the most effective algorithm for fertility preference prediction and evaluates its performance using robust metrics such as accuracy, precision, recall, F1-score, and AUROC. Second, the study enhances the interpretability of machine learning models through SHAP analysis, which quantifies the contribution of each predictor variable, thus addressing the “black-box” nature of machine learning and making the findings more accessible to policymakers and healthcare practitioners. By applying ML models, this study not only advances methodological research in fertility prediction but also offers actionable insights into how sociodemographic factors influence reproductive preferences in Somalia. This dual focus ensures that findings are both interpretable for policymakers and methodologically rigorous for researchers. Third, it provides a comprehensive assessment of the sociodemographic and healthcare access factors influencing fertility preferences, offering evidence-based insights to inform targeted interventions. Finally, this research contributes to the growing body of literature on artificial intelligence applications in reproductive health by addressing the underrepresentation of women’s fertility studies in machine learning research, complementing previous studies that have largely focused on male fertility using Explainable AI techniques as a contrast9,10,11,12,30.To situate this study within the broader academic discourse, it is essential to examine existing research on fertility preferences and the application of machine learning in reproductive health. Prior studies have demonstrated that fertility preferences are shaped by multiple interrelated factors, including age, parity, educational attainment, economic status, geographic location, and cultural norms31,32. For instance, studies have found that older women and those with higher parity are more likely to express a preference to stop childbearing, while higher educational attainment is associated with smaller desired family sizes33,34. Economic considerations, such as household wealth and employment status, also play a crucial role, as financial constraints often influence reproductive intentions35,36. In low-resource settings like Somalia, geographic and healthcare access barriers further impact fertility decisions, with rural and nomadic populations experiencing significant challenges in accessing reproductive health services18,19.The use of machine learning in fertility prediction has gained traction in recent years, with studies demonstrating its potential to improve predictive accuracy and uncover hidden patterns in reproductive health data37,38. Recent research has applied machine learning techniques such as Random Forest, Support Vector Machines, and XGBoost to analyze male fertility, employing Explainable AI methods to interpret model outputs9,11,39,40. Notably, studies have unboxed industry-standard AI models for male fertility prediction using SHAP, highlighting the decision-making process in classification models10,11. Additionally, research has applied Explainable AI with Extreme Gradient Boosting and SMOTE for male fertility prediction, further emphasizing the potential of AI-based tools in reproductive health analytics11,41. However, these studies have primarily focused on infertility rather than fertility preferences. By shifting the focus to predicting fertility preferences among women, this study extends the existing literature by providing insights into reproductive decision-making rather than infertility diagnosis. This distinction is crucial for developing policy-driven interventions that align with family planning programs and public health goals.By addressing these research gaps and leveraging advanced analytical techniques, this study aims to develop an interpretable ML framework for predicting fertility preferences among women in Somalia. This research extends the application of ML beyond fertility diagnosis to fertility preference modeling, filling a critical gap in reproductive health analytics. This approach not only enhances methodological rigor but also provides actionable insights for policymakers and healthcare practitioners. By integrating predictive analytics with Explainable AI, the study offers a transparent and data-driven approach to informing family planning policies, particularly in high-fertility, low-resource settings. The findings have significant implications for designing targeted interventions that improve reproductive health outcomes and promote informed decision-making in family planning programs.Key contributionsThis study makes the following key contributions:This research pioneers the application of machine learning models to predict fertility preferences in Somalia, a data-scarce region where traditional demographic analysis is often limited, offering a new approach to understanding population dynamics.The study conducts a rigorous comparative evaluation of multiple AI models, systematically identifying the most effective approach based on key performance metrics, thereby providing a robust methodology for future research in similar contexts.The study goes beyond “black-box” predictions by employing SHAP analysis to enhance the interpretability of model decisions, revealing key demographic and socioeconomic factors influencing fertility preferences and providing actionable insights for policymakers.The research establishes a systematic methodological framework for integrating AI techniques into demographic research in low-resource settings, offering a valuable template and guidelines for future studies and interventions.MethodsStudy design and data sourceThis study employed a cross-sectional design, utilizing secondary data from the 2020 Somalia Demographic and Health Survey (SDHS). The SDHS is a nationally representative household survey conducted by the Somalia Ministry of Health, in partnership with international organizations. Utilizing a stratified, multistage sampling approach, the SDHS collected data through face-to-face interviews with women aged 15–49 years across diverse regions of Somalia. For this analysis, the Individual Recode (IR) dataset within the SDHS was utilized, focusing on women who reported their place of delivery. The final analytical sample comprised 8,951 eligible women.Study variablesThe outcome variable, ‘fertility preference,’ was dichotomized into ‘desire for no more children’ (0) and ‘desire to have another child’1. Women who were undecided, sterilized, or declared infecund were excluded, as these categories did not provide unambiguous information regarding current fertility intentions. Fertility preference was assessed based on the participant’s stated preference for more children at the time of the survey, aligning with the standard approach used in DHS to capture current fertility intentions which is time-bound to next two years. The predictor variables for the study included sociodemographic characteristics, such as age (categorized into age groups), education level (no education, primary, secondary, and tertiary), wealth index (categorized into quintiles), marital status (married, widowed, divorced, single), residence (urban, rural, nomadic), region of residence, employment status, number of births in the past five years, total number of children born, and distance to the nearest health facility.Data processing and analysisData analysis was performed using a mixed method approach. Initially, exploratory and statistical analyses were conducted using STATA 17. Following this, the main data analysis was conducted in a Python 3.10 environment utilizing a Jupyter Notebook. This method utilizes robust libraries, such as Pandas, NumPy, Scikit-learn, Matplotlib, SHAP, SciPy, and Seaborn, facilitating effective data manipulation, exploration, visualization, model development, and evaluation of feature importance.Data pre-processingThe raw SDHS data underwent extensive pre-processing to ensure its appropriateness for machine learning applications. Outliers in continuous variables were detected using the Tukey method, but their impact was minimal, so no transformations or removals were necessary. For categorical variables, outliers were either merged with existing categories or removed if they were rare and did not hold analytical significance. Since most variables were categorical, normalization was not required. The data cleaning process also addressed inconsistencies, managed missing values, and refined feature engineering by converting selected continuous variables into categorical ones where suitable. This approach enhanced model interpretability and improved robustness by simplifying predictor-outcome relationships.Addressing class imbalance using SMOTEAn initial assessment indicated class imbalance in the outcome variable, with a preference for no more children being underrepresented. To tackle this issue and improve model performance, the Synthetic Minority Over-sampling Technique (SMOTE) was utilized. SMOTE addresses class imbalance by creating synthetic samples for the minority class through interpolation between the existing instances. This process results in a more balanced dataset, allowing the model to learn effectively from both classes and potentially enhance the predictive accuracy for the underrepresented class.Feature selectionAn extensive feature selection process was undertaken to identify the most significant predictors of fertility preference. Exploratory data analysis (EDA) methods, including descriptive statistics and visualizations, offer valuable insights into the distribution of variables and their relationships with outcomes. Bivariate analysis was used to assess the associations between individual predictors and fertility preferences. To further refine the selection of features, Recursive Feature Elimination (RFE) was used to systematically eliminate less important predictors. Additionally, Cramer’s V statistic was applied to evaluate the correlations among predictors, thereby reducing multicollinearity and enhancing the robustness of the final feature set. This integrated approach, which combined statistical analysis, machine learning methods, and a review of the existing literature, resulted in a well-rounded set of predictors for model development.Feature importanceThe assessment of feature importance was conducted using SHapley Additive exPlanations (SHAP) values. SHAP offers a model-agnostic and consistent method for elucidating the contribution of each predictor variable to predictions made for fertility preferences. By assigning an importance score to each feature, SHAP provides critical insights into how individual predictors affect a model’s output. This analysis facilitates a deeper understanding of the relative significance of various factors in predicting outcomes related to fertility preferences.Model developmentTo capture the multifaceted nature of fertility preferences, we selected seven machine learning models, encompassing a diverse range of learning strategies: linear (Logistic Regression), kernel-based (Support Vector Machine), tree-based (Decision Tree, Random Forest), distance-based (K-Nearest Neighbors), and boosting (XGBoost, Gradient Boosting Machine) approaches. These models were chosen to allow for a comparative evaluation of predictive performance across different modeling paradigms. Specifically, Logistic Regression was utilized as a baseline model, while Support Vector Machine was explored for its effectiveness in handling complex relationships. Tree-based models, including Decision Tree and Random Forest, leveraged ensemble techniques to enhance accuracy. K-Nearest Neighbors classified data by assessing the proximity to neighboring points. Finally, Gradient Boosting and XGBoost built models iteratively to improve performance. The algorithms’ effectiveness in predicting fertility preferences was evaluated based on metrics such as accuracy, precision, recall, and F1-score, as well as their capacity to identify key influencing factors.Model training and evaluationTo ensure a robust model performance, the dataset was split into training (80%) and testing (20%) sets. The models were trained using the training set and then evaluated on the unseen test set using a comprehensive array of performance metrics, including accuracy, precision, recall, F1-score, Area Under the Receiver Operating Characteristic Curve (AUROC), and confusion matrices. To further enhance the generalizability of the model and reduce the likelihood of overfitting, stratified k-fold cross validation (k = 5) was performed. This technique systematically divides the dataset into 5 subsets, ensuring that each fold maintains the same class distribution as the full dataset. The model was iteratively trained and evaluated across these folds, and the final performance metrics were averaged to provide a reliable and stable estimate of its predictive capability.Model selectionThe selection of the model was based on a thorough evaluation of the various performance metrics. The confusion matrix provided an in-depth analysis of the model predictions, categorizing them into true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN). Accuracy, which reflects the overall proportion of correct predictions, was used as the key metric. Precision measures the ratio of true positive predictions to all predicted positive cases, while recall (sensitivity) assesses the proportion of actual positive cases that were correctly identified. The F1-score, which balances precision and recall, offers a comprehensive evaluation of model performance. By comparing these metrics across all seven machine learning algorithms, the model demonstrating the most favorable combination of performance indicators was chosen as the optimal model for predicting fertility preferences (Fig. 1).Fig. 1Machine learning workflow for fertility preference prediction in Somalia.Full size imageResultsSociodemographic characteristicsThe study included 8,951 women aged 15–49 years, representing diverse sociodemographic backgrounds across Somalia (Table 1). The largest age group was 25–29 years (23.99%), whereas women aged 45–49 years constituted the smallest group (5.10%). Most participants had no formal education (83.16%), and only 1.38% achieved tertiary education. Nearly half (42.98%) of the respondents resided in urban areas, while 31.91% were nomadic. Regarding wealth status, the lowest quintile accounted for 22.55% of the participants and 88.29% were currently married. Distance to health facilities was reported as a major problem by 62.47% of the women, and only 7.95% were employed. Births in the last five years were most common among women who reported two births (29.99%), while 9.81% had no children ever born.Table 1 Sociodemographic characteristics.Full size tablePredictors of fertility preferencesTable 2 presents the results of logistic regression analyses, serving as a baseline model for comparison. The table summarizes the associations between sociodemographic factors and fertility preferences. Associations are presented as both crude (COR) and adjusted odds ratios (AOR). Age emerged as a significant predictor, with women aged 45–49 years being over five times more likely to prefer no more children compared to those aged 15–19 years (AOR = 5.29; 95% CI: 3.16, 8.87). Higher education levels were associated with reduced odds of desiring no more children, with primary education showing a significant protective effect (AOR = 0.56; 95% CI: 0.42, 0.76). Married women were less likely to report a preference for no more children compared to widowed women (AOR = 5.60; 95% CI: 4.25, 7.40). Additionally, distance to health facilities, employment status, and the total number of children born significantly influenced fertility preferences. For instance, women with seven or more children were three times as likely to prefer no additional children compared to those with no children (AOR = 3.17; 95% CI: 2.01, 5.02).Table 2 Logistic regression (COR and AOR) of factors associated with fertility preference.Full size tableModel performance evaluationTo evaluate the performance of various machine learning algorithms in predicting fertility preferences among reproductive women in Somalia, we employed seven different models: Logistic Regression (LR), Support Vector Machine (SVM), K-Nearest Neighbors (KNN), Decision Tree (DT), Random Forest (RF), Gradient Boosting (GB), and XGBoost (XGB). The models were assessed using a range of performance metrics, including accuracy, precision, recall, F1-score, and the Area Under the Receiver Operating Characteristic Curve (AUROC). The Random Forest model outperformed the other models across most metrics, achieving the highest accuracy (81%), precision (78%), recall (85%), F1-score (82%), and AUROC (0.81). Confusion matrix analysis revealed that the RF model minimized false negatives (245) while maintaining a high true-positive rate (1,251) and true-negative rate (1,397). This minimization of false negatives is particularly important in this context, as failing to identify women who desire more children could limit the impact of targeted reproductive health interventions. The high true-positive and true-negative rates further demonstrate the model’s reliability in correctly classifying women’s fertility preferences. These findings highlight the robustness and suitability of the RF model for predicting fertility preferences (Table 3; Figs. 2; Table 3). To provide a comprehensive evaluation of model performance, we used accuracy to measure the overall proportion of correct predictions. Precision was used to assess the model’s ability to correctly identify women with a preference for more children, while recall measured the model’s ability to capture all women with that preference. The F1-score, which balances precision and recall, was crucial for optimizing the model’s predictive capability. Finally, AUROC was used to evaluate the model’s ability to discriminate between the two classes.Table 3 Performance evaluation metrics and confusion matrix for ML models in predicting fertility Preferences.Full size tableFig. 2Model evaluation metrics for all models.Full size imageAUROC curve analysisThe Receiver Operating Characteristic (ROC) curve is a graphical representation of a model’s diagnostic ability, plotting the true positive rate against the false positive rate at various threshold settings. The Area Under the ROC Curve (AUROC) provided a single metric for evaluating the overall performance of the model. Figure 3 shows the ROC curves for all seven models, with the AUROC values indicated in the legend. The Random Forest model achieved the highest AUROC of 0.89, followed closely by XGBoost (0.86), and Gradient Boosting (0.80). The high AUROC values suggest that these models have a strong ability to distinguish between the two fertility preference classes.Fig. 3ROC curve for all models.Full size imageFeatures importance analysis using SHAPTo evaluate the contribution of each feature to the model’s predictions, we employed SHapley Additive exPlanations (SHAP) values. SHAP values provide a unified measure of feature importance, indicating how each feature influences the model’s output by calculating the contribution of each feature to the difference between the actual prediction and the average prediction. Figure 4 presents the SHAP beeswarm plot, summarizing the impact and ranking of each feature on model predictions. Features are ranked by importance, with age group being the most influential. The color gradient (blue to red) represents feature values from low to high, respectively. Figure 4 displays the SHAP feature importance plot, confirming that age group is the strongest predictor, followed by region and number of births in the last five years. Figure 5 provides the SHAP dot plot, illustrating the spread and density of SHAP values for each feature and highlighting variability in feature impact across predictions. SHAP analysis revealed age group as the most influential predictor, with younger women exhibiting a higher likelihood of desiring additional children. As confirmed by the beeswarm and feature importance plots, region and number of births in the last five years also played significant roles, reflecting geographical and parity-related variations in fertility preference. The wealth index and education level had moderate effects, suggesting that economic and educational empowerment may influence reproductive decisions. Notably, distance to healthcare facilities emerged as a key factor, with SHAP values indicating considerable variability in its effect on fertility preference, ranging from a strong negative impact (reduced preference) for women in remote areas to a moderate positive impact (increased preference) for women with better access. The SHAP feature importance and beeswarm plots consistently ranked these factors as key predictors, demonstrating their contribution to fertility preference modeling.Fig. 4SHAP beeswarm plot (summary plot).Full size imageFigure 5 shows the SHAP feature importance plot, which ranks the features based on their mean absolute SHAP values. This plot confirms that age group is the most important feature, followed by “region” and number of births.Fig. 5SHAP feature Importance plot.Full size imageFigure 6 provides a SHAP dot plot, illustrating the distribution of SHAP values for each feature. This plot helps visualize the spread and density of the SHAP values, providing insights into the variability and impact of each feature.Fig. 6SHAP dot plot.Full size imageDiscussionThis study pioneers the application of machine learning models to predict fertility preferences among women of reproductive age in Somalia, a region where traditional demographic analysis is often constrained by data limitations. By leveraging machine learning techniques, this study offers a new approach to understanding population dynamics, particularly in data-scarce settings. The findings demonstrate the feasibility and value of employing machine learning methods to analyze fertility trends in contexts where conventional statistical models may struggle to capture non-linear interactions42,43. Unlike traditional approaches, which often assume linear relationships, machine learning models provide a more flexible and scalable framework for uncovering complex patterns7,44. For instance, this study identified significant non-linear relationships between women’s education levels, economic status, and access to healthcare, which are crucial factors in understanding fertility preferences. The capacity of machine learning to reveal these interactions aligns with emerging evidence advocating for the integration of artificial intelligence into demographic research to enhance analytical power and predictive accuracy37,45,46.A key contribution of this study is the identification of important predictors influencing fertility preferences. The results indicate that age group, region, number of births in the last five years, number of children ever born, marital status, wealth index, education level, residence, distance to health facilities, and employment status play significant roles in shaping women’s reproductive decisions. These findings align with previous studies emphasizing the role of sociodemographic and economic factors in fertility preferences1,43,47,48,49. Several studies have emphasized the importance of factors such as parity, age, and access to healthcare in shaping fertility preferences1,50,51 [e.g., Ahinkorah et al., 2021; Khan et al., 2023]. Our findings reinforce these observations, highlighting that predictive modeling can complement existing evidence and support program design. To enhance model interpretability, this study employed SHapley Additive exPlanations (SHAP) analysis to quantify the contribution of each predictor variable to fertility preferences. SHAP results confirmed that age, education, wealth index, marital status, and number of children ever born were the most influential factors. This approach addressed concerns about machine learning models functioning as “black boxes” by providing actionable insights for policymakers10,52. Older women and those with higher parity were more likely to prefer stopping childbearing, a pattern well documented in the literature and often attributed to the increasing financial, physical, and emotional demands of raising multiple children53,54,55. Additionally, women who perceived distance to health facilities as a barrier were more likely to prefer stopping childbearing, reflecting the persistent challenges of healthcare access in Somalia, particularly in rural and nomadic communities17,18,29,56. These findings emphasize the need for targeted interventions such as mobile clinics and community-based family planning programs to improve healthcare accessibility and support informed fertility decision-making25,57.A comparative evaluation of machine learning models revealed that the Random Forest model outperformed other algorithms, including Logistic Regression, across key performance metrics such as accuracy, precision, recall, and F1-score, showing the highest performance with an AUROC value of 0.97, accuracy of 90%, precision of 91%, recall of 92%, and F1-score of 0.91. Random Forest’s ensemble nature, which combines predictions from multiple decision trees, is likely a key factor in its success. This approach reduces the risk of overfitting, a common challenge in complex datasets, and allows the model to effectively learn intricate, non-linear patterns and relationships between variables. It is important to consider what these metrics tell us: accuracy indicates the overall correctness of the model’s predictions, precision measures how often the model correctly predicts a woman does want more children when it says she does, and recall measures how often the model correctly identifies women who actually want more children. The F1-score provides a balance between precision and recall. In this study, prioritizing a high F1-score was essential to minimize both false positives (incorrectly predicting a woman wants more children) and false negatives (incorrectly predicting a woman does not want more children), both of which have significant implications for designing effective interventions. The Random Forest model achieved an accuracy of 81% compared to 68% for Logistic Regression, demonstrating its superior ability to capture non-linear relationships and complex feature interactions. While Random Forest offered the best overall accuracy and F1-score, it’s important to note that XGBoost had a higher number of true positives, and KNN performed comparably on recall. These nuances suggest that the optimal model choice may depend on specific outcome priorities, such as minimizing false negatives versus maximizing precision.While Logistic Regression identifies statistically significant predictors, machine learning models like Random Forest offer greater predictive accuracy by uncovering complex, nonlinear interactions, which are crucial as the relationship between factors like education level or wealth index and fertility preferences is rarely linear. For instance, SHAP values highlight not only which variables matter but also the direction and strength of their influence per individual prediction, thus enabling more nuanced understanding. The greater predictive accuracy of Random Forest, as evidenced by the higher F1-score and AUROC, translates to more reliable identification of women with specific fertility preferences, which is vital for resource-constrained settings like Somalia where accurate targeting of interventions is essential to maximize impact. SHAP analysis further enhances the value of the Random Forest model by providing a more granular understanding of the predictors. Unlike Logistic Regression, which provides a single coefficient indicating the direction and strength of a predictor’s average effect, SHAP values show how each predictor influences individual women’s preferences. This allows for personalized interventions, recognizing that the same factor (e.g., distance to a health facility) may have varying degrees of influence on different women. Therefore, the nuanced understanding gained from machine learning and SHAP analysis can significantly improve the design and implementation of family planning programs. For instance, instead of a blanket approach to increasing education, interventions can be tailored to address specific educational barriers that most strongly influence fertility preferences within certain subgroups.The interpretation of metric values, such as the 78% precision and 81% accuracy observed, is highly context-dependent, and there are no universal thresholds for ‘good’ or ‘bad’ performance. In this study, the 13% increase in accuracy from Logistic Regression to Random Forest, and the corresponding improvement in the F1-score, represent a substantial gain in predictive performance. Given the resource-constrained setting of Somalia, even small improvements in accuracy can translate to more efficient targeting of interventions and better outcomes for women. Researchers must also consider the trade-offs between metrics. For instance, if the primary goal were to capture every woman who desires more children (high recall), a model with slightly lower precision might be acceptable. However, we prioritized a balanced approach, reflected in the F1-score, to minimize both false positives and false negatives, as both types of errors have implications for intervention effectiveness. Achieving an 81% accuracy in predicting fertility preferences in Somalia, a region with complex sociocultural dynamics and data limitations, indicates a robust model. While higher accuracies might be attainable in less challenging contexts, our results demonstrate the Random Forest model’s suitability for informing evidence-based policymaking in this specific setting. Future research should explore the applicability of these metrics and models in other similar data-limited contexts.While Logistic Regression remains widely used due to its interpretability, its assumption of linear relationships may oversimplify fertility decision-making processes42,44,52. These results align with existing studies that highlight the advantages of ensemble-based approaches like Random Forest in demographic research37,38. The findings underscore the importance of systematically evaluating multiple machine learning models to determine the most effective approach for specific research applications. This comparative analysis provides a methodological framework that can be adapted for future studies on fertility preferences and other demographic phenomena, particularly in data-limited settings48,50. In particular, machine learning excels at capturing complex non-linear relationships between predictors and the outcome variable, which is a significant advantage in this context. While logistic regression assumes a linear relationship between the log-odds of the outcome and the predictors, machine learning models, such as Random Forest, can model more intricate patterns. This is because Random Forest, for example, can partition the data space into smaller regions with different relationships, allowing it to adapt to non-linearities. Our analysis identified several key sociodemographic factors influencing fertility preferences. Both the logistic regression model and the SHAP analysis highlighted the significant roles of age, parity, and region1,58. The logistic regression model provided a traditional understanding of these associations in terms of odds ratios (Table 2). However, SHAP analysis offered additional, more nuanced insights. Specifically, SHAP revealed case-specific impact scores, demonstrating how the influence of these factors varies across different subpopulations. For instance, while both methods identified age as an important predictor, SHAP showed the magnitude of age’s influence varied depending on other factors. Moreover, SHAP analysis, derived from the Random Forest model, implicitly captured interactions between variables, such as the interaction between age and distance to a health facility. These interaction effects, while potentially present in the data, are not explicitly modeled in the logistic regression.To enhance model interpretability, this study employed SHapley Additive exPlanations (SHAP) analysis to quantify the contribution of each predictor variable to fertility preferences. SHAP results confirmed that age, education, wealth index, marital status, and number of children ever born were the most influential factors. This approach addressed concerns about machine learning models functioning as “black boxes” by providing actionable insights for policymakers10,59. For example, the quantification of education’s impact on fertility preferences supports policies promoting female education as a means to influence reproductive choices31,32,60. Women with primary education were less likely to prefer stopping childbearing than those with no formal education, a finding consistent with research demonstrating the transformative role of education in reproductive decision-making31,61. Education enhances women’s autonomy, increases awareness of family planning options, and empowers them to make informed choices about childbearing. Given Somalia’s low female education rates, expanding access to education could have substantial implications for fertility preferences and broader reproductive health outcomes62.Beyond its empirical contributions, this study establishes a systematic methodological framework for integrating artificial intelligence into demographic research in low-resource environments. The framework includes key steps such as data preprocessing, model selection, performance evaluation, and interpretability analysis, offering a structured guide for future applications. The successful implementation of this framework underscores the potential of artificial intelligence to enhance demographic studies and inform evidence-based policymaking in regions where traditional data collection methods are constrained42,43,63. Future research can build upon this approach by incorporating additional data sources, exploring more advanced machine learning algorithms, and assessing the long-term effects of reproductive health interventions16,64. The integration of machine learning with demographic research has the potential to transform fertility analysis by uncovering hidden patterns in reproductive behavior and facilitating more targeted interventions45,64.LimitationsDespite providing valuable insights, this study has some inherent limitations. The cross-sectional design precludes the establishment of causal relationships between the factors and fertility preferences. Furthermore, the analysis relied on self-reported data, which may be subject to recall or social desirability bias. The study primarily focused on sociodemographic factors, potentially overlooking other influential factors, such as cultural norms, religious beliefs, and access to family planning services. In addition, reliance on secondary data limits the ability to explore specific contextual factors and individual-level experiences that may influence fertility decisions. Another important limitation is the lack of external validation of the developed machine learning models. Future research should prioritize validating these models using independent datasets from similar or different contexts to assess their generalizability and robustness.ConclusionThis study demonstrated the utility of machine learning algorithms, particularly random forests, in predicting fertility preferences among reproductive-aged women in Somalia. By identifying critical sociodemographic determinants, including age group, region, number of births in the last five years, number of children born, marital status, wealth index, education level, residence, distance to health facilities, and employment status, the findings provide actionable insights into reproductive health policies and programs. SHAP analysis enhanced the interpretability of the ML models, enabling a nuanced understanding of the factors influencing fertility preferences. These results emphasize the potential of integrating advanced analytical techniques with traditional approaches to address unmet needs for family planning and to improve maternal and child health outcomes in low-resource settings. Future research should continue to explore the application of machine learning in reproductive health, expanding its scope to diverse populations and integrating longitudinal data to capture dynamic changes in fertility preferences. Furthermore, future research should externally validate the model on independent datasets or in other sub-Saharan African contexts to enhance generalizability.Data availabilityThe data supporting the findings of this study are publicly available in the 2020 Somali Demographic and Health Survey (SDHS), which can be accessed at https://microdata.nbs.gov.so/index.php/catalog/50. All data were obtained from resources available in the public domain.ReferencesAhinkorah, B. O. et al. Socio-economic and demographic factors associated with fertility preferences among women of reproductive age in ghana: Evidence from the 2014 demographic and health survey. Reproduct. Health. 18 (1), 2 (2021).PubMed  PubMed Central  Google Scholar Odusina, E. K. et al. Fertility preferences among couples in nigeria: A cross sectional study. Reproduct. Health. 17 (1), 92 (2020).PubMed  PubMed Central  Google Scholar Duminy, J. et al. Urban family planning in Low- and Middle-Income countries: A critical scoping review. Front. Glob. Womens Health. 2, 749636 (2021).PubMed  PubMed Central  Google Scholar Hellwig, F. et al. Policies for expanding family planning coverage: Lessons from five successful countries. Front. Public. Health. 12, 1339725 (2024).PubMed  PubMed Central  Google Scholar Khan, M. N. et al. Improving the uptake of contraception. Somalia Bull. World Health Organ. 102 (1), 75 (2023).PubMed  Google Scholar Mahasneh, I. & Ebrahim, F. The epidemiological declining in the human fertility rate in the Arab world for 10 years period 2011–2021. Middle East. Fertil. Soc. J. 29 (1), 47 (2024).Google Scholar Ley, C. et al. Machine learning and conventional statistics: Making sense of the differences. Knee Surg. Sports Traumatol. Arthrosc. 30 (3), 753–757 (2022).PubMed  Google Scholar Rajula, H. S. R., Verlato, G., Manchia, M., Antonucci, N. & Fanos, V. Comparison of conventional statistical methods with machine learning in medicine: Diagnosis, drug development, and treatment. Medicina 56 (9), 455 (2020).PubMed  PubMed Central  Google Scholar Feretzakis, G. et al. Integrating Shapley values into machine learning techniques for enhanced predictions of hospital admissions. Appl. Sci. 14 (13), 5925 (2024).CAS  Google Scholar GhoshRoy, D., Alvi, P. A. & Santosh, K. C. Unboxing industry-standard ai models for male fertility prediction with SHAP. Healthcare 11 (7), 929 (2023).PubMed  PubMed Central  Google Scholar GhoshRoy, D., Alvi, P. A. & Santosh, K. C. Explainable AI to predict male fertility using extreme gradient boosting algorithm with SMOTE. Electronics 12 (1), 15 (2023).Google Scholar Schmeis Arroyo, V., Iosa, M., Antonucci, G. & De Bartolo, D. Predicting male infertility using artificial neural networks: A review of the literature. Healthcare 12 (7), 781 (2024).PubMed  PubMed Central  Google Scholar GhoshRoy, D., Alvi, P. A. & Santosh, K. AI tools for assessing human fertility using risk factors: A state-of-the-art review. J. Med. Syst. 47 (1), 91 (2023).PubMed  Google Scholar GhoshRoy, D., Alvi, P. A. & Santosh, K. Leveraging sampling schemes on skewed class distribution to enhance male fertility detection with ensemble AI learners. Int. J. Pattern Recogn. Artif. Intell. 38 (02), 2451003 (2024).Google Scholar Doupe, P., Faghmous, J. & Basu, S. Machine learning for health services researchers. Value Health. 22 (7), 808–815 (2019).PubMed  Google Scholar Ponce-Bobadilla, A. V., Schmitt, V., Maier, C. S., Mensing, S. & Stodtmann, S. Practical guide to SHAP analysis: Explaining supervised machine learning model predictions in drug development. Clin. Transl Sci. 17 (11), e70056 (2024).PubMed  PubMed Central  Google Scholar Ahmed, Z. et al. Understanding the factors affecting the humanitarian health and nutrition response for women and children in Somalia since 2000: A case study. Confl. Health. 14 (1), 35 (2020).PubMed  PubMed Central  Google Scholar Duale, H. A., Farah, A., Salad, A., Gele, S. & Gele, A. Constraints to maternal healthcare access among pastoral communities in the Darussalam area of Mudug region, Somalia a qualitative study. Front. Public. Health. 11, 1210401 (2023).PubMed  PubMed Central  Google Scholar Wulifan, J. K., Dordah, A. D. & Sumankuuro, J. Nomadic pastoralists’ experience accessing reproductive and maternal healthcare services in low and middle-income countries: A contextual scoping review. Pastoralism 12 (1), 47 (2022).Google Scholar Cronin, C. J., Guilkey, D. K. & Speizer, I. S. The effects of health facility access and quality on family planning decisions in urban Senegal. Health Econ. 27 (3), 576–591 (2018).PubMed  Google Scholar Yücel, U., Çiçeklioğlu, M., Öcek, Z. A. & Varol, Z. S. Access to primary health care family planning services and contraceptive use in disadvantaged women: A qualitative study. Eur. J. Contracept. Reproduct. Health Care. 25 (5), 327–333 (2020).Google Scholar Adler, A., Biggs, M. A., Kaller, S., Schroeder, R. & Ralph, L. Changes in the frequency and type of barriers to reproductive health care between 2017 and 2021. JAMA Netw. Open. 6 (4), e237461–e237461 (2023).PubMed  PubMed Central  Google Scholar Shatilwe, J. T., Kuupiel, D. & Mashamba-Thompson, T. P. Evidence on access to healthcare information by women of reproductive age in low-and middle-income countries: Scoping review. Plos One. 16 (6), e0251633 (2021).CAS  PubMed  PubMed Central  Google Scholar Dotse-Gborgbortsi, W. et al. Distance is a big problem: A geographic analysis of reported and modelled proximity to maternal health services in Ghana. BMC Pregnancy Childbirth. 22 (1), 672 (2022).PubMed  PubMed Central  Google Scholar Mseke, E. P., Jessup, B. & Barnett, T. Impact of distance and/or travel time on healthcare service access in rural and remote areas: A scoping review. J. Transp. Health. 37, 101819 (2024).Google Scholar Tanou, M., Kishida, T. & Kamiya, Y. The effects of geographical accessibility to health facilities on antenatal care and delivery services utilization in benin: A cross-sectional study. Reproduct. Health. 18, 205 (2021).PubMed  PubMed Central  Google Scholar Chatterjee, E. & Sennott, C. Fertility intentions and maternal health behaviour during and after pregnancy. Popul. Stud. 74 (1), 55–74 (2020).Google Scholar Shumet, T. & Geda, N. R. Impacts of inequalities in utilization of key maternal health service on fertility preference among high parity women in four selected regions of Ethiopia. BMC Women’s Health. 24 (1), 590 (2024).PubMed  PubMed Central  Google Scholar Dahab, R. & Sakellariou, D. Barriers to accessing maternal care in low income countries in Africa: A systematic review. Int. J. Environ. Res. Public Health. 17 (12), 4292 (2020).PubMed  PubMed Central  Google Scholar Uddin, S., Khan, A., Hossain, M. E. & Moni, M. A. Comparing different supervised machine learning algorithms for disease prediction. BMC Med. Inf. Decis. Mak. 19 (1), 281 (2019).Google Scholar Berger, H. & Dasré, A. Religious affiliation, education, and fertility in sub-Saharan Africa. World Dev. 184, 106723 (2024).Google Scholar Bongaarts, J. Trends in fertility and fertility preferences in sub-Saharan Africa: The roles of education and family planning programs. Genus 76 (1), 32 (2020).Google Scholar Idris, I. B. et al. Women’s autonomy in healthcare decision making: A systematic review. BMC Womens Health. 23, 643 (2023).PubMed  PubMed Central  Google Scholar Tan, K. et al. Effects of economic uncertainty and socioeconomic status on reproductive timing: A life history approach. Curr. Res. Ecol. Soc. Psychol. 3, 100040 (2022).Google Scholar Guo, C., Yang, P. & Mu, Y. Expectations of improvement of socioeconomic status throughout the life course as a component for promoting fertility intentions. China CDC Wkly. 5 (16), 365 (2023).PubMed  PubMed Central  Google Scholar Matera, C. et al. Perceived economic uncertainty and fertility intentions in couples: A dyadic extension of the theory of planned behaviour. J. Fam Econ. Iss. 44 (4), 790–806 (2023).Google Scholar Kigo, S. N., Omondi, E. O. & Omolo, B. O. Assessing predictive performance of supervised machine learning algorithms for a diamond pricing model. Sci. Rep. 13 (1), 17315 (2023).ADS  CAS  PubMed  PubMed Central  Google Scholar Prathap, K. R. & Bhavani, R. Study comparing classification algorithms for loan approval predictability (Logistic regression, XG boost, random forest, decision Tree). J. Surv. Fisheries Sci. 10 (1S), 2438–2447 (2023).Google Scholar Band, S. S. et al. Application of explainable artificial intelligence in medical health: A systematic review of interpretability methods. Inf. Med. Unlocked. 40, 101286 (2023).Google Scholar Paudel, P., Saud, R., Karna, S. K. & Bhandari, M. Determining the Major Contributing Features to Predict Breast Cancer Imposing ML Algorithms with LIME and SHAP. In 2023 International Conference on Electrical, Computer and Energy Technologies (ICECET) [Internet]. IEEE; 2023 [cited 2024 Nov 23]. pp. 1–7. https://ieeexplore.ieee.org/abstract/document/10389217/Sowjanya, A. M. & Mrudula, O. Effective treatment of imbalanced datasets in health care using modified SMOTE coupled with stacked deep learning algorithms. Appl. Nanosci. 13 (3), 1829–1840 (2023).ADS  CAS  PubMed  Google Scholar Kassaw, E. A., Abate, B. B., Enyew, B. M. & Sendekie, A. K. The application of machine learning approaches to classify and predict fertility rate in Ethiopia. Sci. Rep. 15 (1), 2562 (2025).CAS  PubMed  PubMed Central  Google Scholar Tadese, Z. B. et al. Exploring machine learning algorithms for predicting fertility preferences among reproductive women in Nigeria. Front. Digit. Health 6:1495382 .Barnett-Itzhaki, Z. et al. Machine learning vs. classic statistics for the prediction of IVF outcomes. J. Assist. Reprod. Genet. 37 (10), 2405–2412 (2020).PubMed  PubMed Central  Google Scholar Hassan, A. A., Muse, A. H. & Chesneau, C. Machine learning study using 2020 SDHS data to determine poverty determinants in Somalia. Sci. Rep. 14 (1), 5956 (2024).ADS  CAS  PubMed  PubMed Central  Google Scholar Islam, T., Meade, N., Carson, R. T., Louviere, J. J. & Wang, J. The usefulness of socio-demographic variables in predicting purchase decisions: Evidence from machine learning procedures. J. Bus. Res. 151, 324–338 (2022).Google Scholar Afferri, A. et al. Policy action points and approaches to promote fertility care in the gambia: Findings from a mixed-methods study. PLOS ONE. 19 (5), e0301700 (2024).CAS  PubMed  PubMed Central  Google Scholar Mohamud, L. A. & Nasir, J. A. Role of proximate determinants on the fertility rate among currently married women in Somalia via Bongaart’s model: Findings from 2018-19 Sdhs Data. 2024 [cited 2025 Jan 8]. https://www.researchsquare.com/article/rs-4752428/latestNyarko, S. H. Socioeconomic determinants of cumulative fertility in Ghana. Plos One. 16 (6), e0252519 (2021).CAS  PubMed  PubMed Central  Google Scholar Khan, N. U. et al. Fertility patterns in pakistan: A comparative analysis of family planning trends across different geographic regions. Rural Remote Health. 24 (3), 1–8 (2024).Google Scholar Lotfi, R., Rajabi Naeeni, M., Rezaei, N., Farid, M. & Tizvir, A. Desired numbers of children, fertility preferences and related factors among couples who referred to pre-marriage counseling in Alborz province, Iran. Int. J. Fertil. Steril. 11 (3), 211–219 (2017).PubMed  PubMed Central  Google Scholar Weigard, A. & Spencer, R. J. Benefits and challenges of using logistic regression to assess neuropsychological performance validity: Evidence from a simulation study. Clin. Neuropsychol. 37 (1), 34 (2023).PubMed  Google Scholar Doepke, M., Hannusch, A., Kindermann, F. & Tertilt, M. The economics of fertility: A new era. In Handbook of the Economics of the Family [Internet]. Elsevier; 2023 [cited 2025 Jan 13]. pp. 151–254. https://www.sciencedirect.com/science/article/pii/S2949835X23000034Jiang, Y. & Yang, F. Motherhood health penalty: Impact of fertility on physical and mental health of Chinese women of childbearing age. Front. Public. Health. 10, 787844 (2022).PubMed  PubMed Central  Google Scholar Seshadri, S., Morris, G., Serhal, P. & Saab, W. Assisted conception in women of advanced maternal age. Best Pract. Res. Clin. Obstet. Gynecol. 70, 10–20 (2021).CAS  Google Scholar Ahmed, J. H. J. The social context of family size decisions: The experiences of Somali and Sudanese migrant communities [Internet] [PhD Thesis]. Aston University; [cited 2025 Jan 13]. (2022). https://publications.aston.ac.uk/id/eprint/44679/Sanogo, N. A., Fantaye, A. W. & Yaya, S. Universal health coverage and facilitation of equitable access to care in Africa. Front. Public. Health. 7, 102 (2019).PubMed  PubMed Central  Google Scholar Socio-economic and demographic. factors associated with fertility preferences among women of reproductive age in Ghana: Evidence from the 2014 Demographic and Health Survey | Reproductive Health | Full Text [Internet]. 2024 [cited 2024 May 19]. https://reproductive-health-journal.biomedcentral.com/articles/https://doi.org/10.1186/s12978-020-01057-9Ning, Y. et al. Shapley variable importance cloud for interpretable machine learning. Patterns [Internet]. 2022 [cited 2024 Dec 31];3(4). https://www.cell.com/patterns/fulltext/S2666-3899(22)00025-3Nitsche, N. & Hayford, S. R. Preferences, partners, and parenthood: Linking early fertility desires, marriage timing, and achieved fertility. Demography 57 (6), 1975–2001 (2020).PubMed  Google Scholar Götmark, F. & Andersson, M. Human fertility in relation to education, economy, religion, contraception, and family planning programs. BMC Public. Health. 20 (1), 265 (2020).PubMed  PubMed Central  Google Scholar Frola, A., Delprato, M. & Chudgar, A. Lack of educational access, women’s empowerment and Spatial education inequality for the Eastern and Western Africa regions. Int. J. Educ. Dev. 104, 102939 (2024).Google Scholar Rajpoot, N. K., Singh, P. D., Pant, B. & Tripathi, V. The future of healthcare: A machine learning revolution. In 2023 International Conference on Artificial Intelligence for Innovations in Healthcare Industries (ICAIIHI) [Internet]. Raipur, India: IEEE; [cited 2024 Nov 23]. pp. 1–6. (2023). https://ieeexplore.ieee.org/document/10489320/Bozkurt, S. et al. Reporting of demographic data and representativeness in machine learning models using electronic health records. J. Am. Med. Inform. Assoc. 27 (12), 1878–1884 (2020).PubMed  PubMed Central  Google Scholar Download referencesAcknowledgementsThe authors acknowledge the Somalia National Bureau of Statistics for providing the data available for this study.FundingNone.Author informationAuthors and AffiliationsDepartment of Demography and Social Statistics, Federal University Birnin Kebbi, Birnin Kebbi, Kebbi State, NigeriaJamilu SaniDepartment of Public Health, Ministry of Health, Galmudug, SomaliaSalad HalaneDepartment of Health System Strengthening, Ministry of Health, Galmudug, SomaliaAbdiwali Mohamed AhmedFaculty of Medicine and Health Sciences, SIMAD University, Mogadishu, SomaliaMohamed Mustaf AhmedAuthorsJamilu SaniView author publicationsSearch author on:PubMed Google ScholarSalad HalaneView author publicationsSearch author on:PubMed Google ScholarAbdiwali Mohamed AhmedView author publicationsSearch author on:PubMed Google ScholarMohamed Mustaf AhmedView author publicationsSearch author on:PubMed Google ScholarContributionsJS conceptualized the study, designed the methodology, performed data analysis, visualized the results, and wrote the manuscript. SH and AA contributed by providing critical reviews and editing the manuscript. MMA offered additional insights and technical support during the manuscript preparation. All authors have reviewed and approved the final version of the manuscript.Corresponding authorCorrespondence to Salad Halane.Ethics declarationsCompeting interestsThe authors declare no competing interests.Ethical considerationsThis study employed secondary data from the 2020 Somali Demographic and Health Survey (SDHS), which was conducted following established ethical standards. Ethical approval for this study was obtained from the Somali Ministry of Health. The Institutional Review Board (IRB) of the Ministry of Health (National Research Ethics Committee of the Federal Ministry of Health and Human Services, Mogadishu, Somalia) waived the need for informed consent due to the nature of the study, as it relied solely on secondary data extracted from the 2020 SDHS. All data were analyzed in a manner that ensured participant anonymity, thereby maintaining confidentiality and privacy. Additionally, all methods were performed in accordance with the relevant guidelines.Consent to participateThis research used secondary data from the 2020 Somali Health and Demographic Survey (SHDS), conducted following ethical standards and approved by relevant Somali authorities, including the Directorate of National Statistics and the Ministry of Health. The survey ensured informed consent through voluntary participation and maintained participant anonymity by using anonymous questionnaires. All data were analyzed with strict confidentiality to protect respondents’ privacy in line with both international and Somali ethical guidelines.Additional informationPublisher’s noteSpringer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.Rights and permissionsOpen Access This article is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License, which permits any non-commercial use, sharing, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if you modified the licensed material. You do not have permission under this licence to share adapted material derived from this article or parts of it. The images or other third party material in this article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.Reprints and permissionsAbout this article