Intro
Venous thromboembolism (VTE), including deep vein thrombosis (DVT) and pulmonary embolism (PE), is a leading cause of morbidity and mortality, with an estimated incidence of 7.5–26.9 VTE events per 10 000 person-years. 1 Women have a higher VTE risk due to additional risk factors, including contraceptive use, pregnancy and hormone replacement therapy (HRT). 2 Combined oral contraceptives (COCPs) are among the modifiable risk factors, which are widely used and have been linked with VTE risk, specifically during the first 2 years of use. 3 A meta-analysis reported that women using COCPs may have a 1.5-fold to twofold increased risk, corresponding to approximately 14–20 VTE events per 10 000 woman-years. 4
COCPs are known to induce a hypercoagulable state through different mechanisms, including increased synthesis of procoagulant factors, impaired fibrinolysis and reduced anticoagulant activity. 5 The risk varies based on the type of progestin used, the dose of ethinyl-oestradiol and patient-related risk factors such as advanced age, obesity and underlying thrombophilic disorders. 5 Weighing the risks and benefits is recommended when prescribing COCPs to women with known thrombophilic disorders, a history of VTE or other significant risk factors; however, these may not account for undetected contributors to thrombotic risk. 6 Moreover, risk models are lacking, with those published relying on traditional regression-based methods that may not capture complex interactions between multiple risk factors. 7
Machine learning (ML) has evolved as an effective method to predict various clinical outcomes. They offer the ability to analyse large health-related datasets, generating individualised risk estimates. 8
9 In comparison to traditional methods, ML models can combine demographics, clinical, biological and other information to predict future events. 8
9 They have shown promise in predicting VTE events in different populations, such as patients with cancer, hospitalised patients and those undergoing surgeries. 10 – 12 They outperform commonly used clinical scoring tools, with improved accuracy and the possibility of identifying unknown risk factors. 10 – 12 In this study, we applied several ML models to develop a predictive tool for VTE risk in COCP users to support regulatory and clinical decision-making.
Methods
We employed de-identified electronic health records (EHRs) from the Saudi Real-world Evidence Network (SRWEN). SRWEN links patient-level demographics, diagnoses (using the International Classification of Diseases, 10th revision, Clinical Modification (ICD-10-CM) codes), procedures, prescriptions and laboratory values from healthcare facilities across Saudi Arabia. This study used data from a tertiary healthcare centre that covers five different hospitals across three regions. 13
14
All women (≥14 years) who obtained at least one COCP prescription from July 2016 to December 2023 were included. To allow sufficient baseline covariate capturing, the patient should have had at least 6 months eligibility before the index date (ie, COCP prescription). Patients having any history of VTE, atrial fibrillation, heart valve replacement, coagulation disorders (including antiphospholipid syndrome or thrombophilia), malignancies or undergoing oophorectomy or hysterectomy on anticoagulants were excluded. Patients who have received antiplatelets, chemotherapy or HRT within 6 months pre-index, pregnant women within 12 months pre-index or postpartum within 6 months pre-index were also excluded ( online supplemental figure 1 ).
The date of initial prescription for COCP, third-generation (ethinyl-oestradiol 0.03 mg+desogestrel 0.15 mg or ethinyl-oestradiol 0.03 mg+gestodene 0.075 mg) or fourth-generation (ethinyl-oestradiol 0.035 mg+cyproterone-acetate 2 mg), served as the index date. 15 Prescriptions with overlapping or continuous coverage (≤90-day gap between refills) were considered as one single ‘treatment episode’. If a new prescription follows the gap, a new treatment episode begins as a new observation. Patients were followed from the index date through the completion of the treatment episode plus a 90-day washout period. For treatment episodes with no gap, follow-up is 2 years from the index date or the end of the study period, whichever occurred first. Patients were censored on occurrence of the first VTE event, 2 years following the index date, at study end (ie, 31 December 2023), at COCP discontinuation (ie, end of treatment episode plus 90 days), switching to other COCP, loss to follow-up or death.
This is a retrospective longitudinal study. Eligible women were included at their first COCP prescription. The primary outcome was the first VTE event, defined by the presence of a VTE-related ICD-10-CM code of DVT, PE or other venous thromboses or continuous use of any anticoagulant drug for more than 90 days ( online supplemental table 1 ).
Potential factors included demographic, clinical, pharmacological and procedural variables, which were measured 3–6 months prior to the index date unless they pertained to chronic conditions. Variables were identified through clinical expertise and literature review ( online supplemental table 2 ). Feature selection was applied to address the large number of possible risk factors and was performed exclusively on the training set following data partitioning to prevent information leakage from the test set into the variable selection process. 10
16
A full logistic regression model was fitted on the training set, including all variables as binary indicators (0/1), with the exception of age, which was continuous, and laboratory values, which were ordinal. Variables with zero variance were excluded prior to model fitting. Backward elimination was applied manually, with variables exceeding p>0.50 iteratively removed across reduced models; this threshold was selected because a stricter criterion (p<0.05) retained only four variables and resulted in poorer model performance, with clinical judgement used alongside statistical significance to guide variable retention. Backward elimination was preferred over forward selection, as it is less likely to exclude genuine but weak predictors in rare-event settings.
A Pearson correlation matrix was computed across all candidate training-set variables as a diagnostic check for multicollinearity. Variable pairs with r≥0.60 were flagged for review; no retained variable pairs exceeded this threshold. Final models were retrained with the selected features and revalidated.
Given the number of variables, the limited number of events and the potential for missing data, we applied a combination of ML models ranging from traditional to anomaly-detection methods. Elastic-net penalised logistic regression (EN-LR; combining LASSO and Ridge penalties) was employed to provide regularisation and stabilise coefficient estimates in such a setting of limited events. Random forest (RF) was applied for its robustness to missing values and complex feature interactions. Extreme gradient boosting (XGBoost), selected as the primary model, was used, as it excels at handling tabular medical data. 17 Additionally, Isolation-Forest and one-class support vector machine (SVM) were used as anomaly-detection approaches, as they identify rare or atypical observations that may correspond to true positive outcomes in highly imbalanced datasets. 18
To address class imbalance, both oversampling and undersampling techniques were applied. The synthetic minority oversampling technique (SMOTE) and random oversampling examples (ROSE) generate synthetic minority samples to improve representation of rare outcomes. 19 Random undersampling reduced majority-class (non-VTE) observations using real data only, avoiding synthetic generation. 19
Data were split randomly into training (75%) and test (25%) sets using stratified partitioning (createDataPartition), ensuring the original class distribution was preserved in both sets prior to any resampling or model fitting. The held-out test set remained unmodified throughout the analysis. Resampling techniques (SMOTE, ROSE and undersampling) were performed only on the training data.
Primary performance metrics were area under the curve of the receiver operating characteristic (AUROC) and F1-score, precision and recall. The F1-score was selected as a primary classification metric, as it balances precision and recall into a single measure, offering a more informative assessment of minority-class detection than accuracy alone in severely imbalanced settings. This is particularly pertinent in the present study, where a model predicting all observations as non-events would achieve near-perfect accuracy yet fail entirely to identify true VTE cases. Both 10-fold cross-validation and bootstrap resampling (50 iterations, confirmed stable beyond the fourth decimal place with higher iteration counts) were used to assess the stability of AUROC performance, with a 95% CI derived from the bootstrap procedure.
A descriptive analysis was used summarising baseline characteristics (mean±SD) or median (IQR) for continuous variables and counts (%) for categorical variables stratified by third-generation and fourth-generation COCPs. Following data partitioning and feature selection, models were trained and evaluated on the held-out test set.
As a separate analysis, we reconstructed the treatment episodes using a 30-day gap period to assess robustness across risk windows, as evidence suggests that VTE risk declines within the first month after discontinuation. 20 To ensure reproducibility and transparency, the analysis scripts are provided as online supplemental file 2 . All analyses were performed using R statistical software V.4.4.1.
Results
A total of 24 518 (n=17 512; 52 VTE events) COCP episodes were included, of whom 4505 (18.4%) episodes were in the fourth-generation group and 20 013 (81.6%) episodes in the third-generation group. The mean age was 32.9 (SD ±8.15) years, with the fourth-generation group being younger (28.6 (SD ±7.98) vs 33.9 (SD ±7.86) years; p<0.001). Obesity (7.1% vs 5.2%), liver disease (4.5% vs 2.3%) and polycystic ovary syndrome (45.1% vs 5.8%) were more prevalent in the fourth-generation group (all p<0.001). Diabetes (9.8% vs 6.5%) and thyroid disorders (13.1% vs 10.5%) were more prevalent in the third-generation group (all p<0.001). The most commonly prescribed medications were acetaminophen (43.1%), non-steroidal anti-inflammatory drugs (24.9%), antihistamines (20.7%) and antimicrobials (18.8%). The overall incidence of VTE during follow-up was low (n=52, 0.2%), with no significant difference between groups (p=0.46) ( table 1 ).
COCP, combined contraceptive pill.;
Retained features included any admission within 48 hours before the index, conditions such as rheumatic diseases (sclerosis, systemic lupus and rheumatoid arthritis), thyroid disorders, hypertension, diabetes, varicose veins, hyperlipidaemia, renal disease, trauma and abnormal prothrombin time. As well as age at cohort entry or exposure to any of the following medications: antidepressants, antimicrobials, folic acid, glucocorticoids and proton pump inhibitors. No multicollinearity was detected between predictors (all pairwise correlations <0.60).
Across the original dataset (training ratio 346:1), among supervised models, all showed near-zero classification performance (precision, recall and F1<0.001), reflecting the severe class imbalance. XGBoost achieved the highest CV-AUROC of 54.3% (bootstrap-AUROC: 62.1%), followed by EN-LR (CV-AUROC: 52.7%; bootstrap-AUROC: 58.1%) and RF (CV-AUROC: 47.7%; bootstrap-AUROC: 53.4%). Among the anomaly-detection models, Isolation-Forest outperformed one-class SVM (bootstrap-AUROC: 68.7% vs 62.0%), both with F1-scores of 0.6% ( table 2 ). CV-AUROC values approached random discrimination (range 47.7%–54.3%), reflecting the inherent difficulty of discriminating rare VTE events under severe class imbalance (training ratio 346:1); AUROC is known to be insensitive to minority-class performance in such settings and should be interpreted accordingly.
AUROC, area under the receiver operating characteristic curve; CV, cross-validation; EN-LR, elastic-net logistic regression; RF, random forest; ROSE, random oversampling examples; SMOTE, synthetic minority oversampling technique; SVM, support vector machine; XGBoost, extreme gradient boosting.
Under SMOTE, RF and XGBoost achieved the strongest classification performance, with F1-scores of 84.3% and 81.5%, respectively, and recall of 75.1% and 74.2%, respectively, driven by high precision (96.1% and 90.5%). XGBoost showed a higher CV-AUROC (62.7%) compared with RF (54.7%). EN-LR performed poorly under SMOTE (F1: 2.6%, recall: 100%, CV-AUROC: 63.9%).
Under ROSE, RF and XGBoost again achieved comparable and strong F1-scores (81.8% and 81.6%, respectively), with recall of 78.4% and 76.7%, respectively. XGBoost achieved the highest CV-AUROC of 69.2% compared with RF (59.6%). EN-LR showed improvement in F1-score under ROSE compared with SMOTE (F1: 22.3%, recall: 30.8% and CV-AUROC: 58.4%).
Under undersampling, performance was reduced across all supervised models (F1: 26.5%–37.0%, recall: 47.6%–71.4%, CV-AUROC: 50.9%–57.2%), with EN-LR achieving the highest F1-score (37.0%). Among anomaly-detection models, one-class SVM and Isolation-Forest performed relatively better under undersampling compared with SMOTE and ROSE (F1: 45.8%–50.0%, recall: 42.9%–52.4%), though AUROC remained modest ( table 2 ).
Among the top contributing features, age at cohort entry was the most important predictor in the original dataset, consistently ranking highest across all models. In the ROSE-balanced data, rheumatic diseases and glucocorticoids were the most prominent features, with diabetes showing high importance in anomaly-detection models. In the SMOTE-balanced data, renal disease and glucocorticoid use ranked highest, followed by thyroid diseases and varicose veins. For undersampling models, the most important features were age at cohort entry, rheumatic diseases and trauma ( online supplemental figure 2 ).
Models trained using a 30-day gap period (episodes=28 764; 41 VTE events) produced comparable findings. Under SMOTE, RF and XGBoost maintained high F1-scores (86.0% and 83.8%, respectively), while AUROC values remained modest (CV-AUROC: 48.4% and 52.2%); EN-LR remained low (F1: 4.7%, CV-AUROC: 43.5%). Under ROSE, RF and XGBoost again performed well (F1: 89.0%, CV-AUROC: 68.6%; F1: 87.8%, CV-AUROC: 68.2%, respectively), while EN-LR showed moderate performance (F1: 21.7%, CV-AUROC: 63.2%). Under undersampling, performance was reduced across all models compared with SMOTE and ROSE; EN-LR achieved an F1-score of 13.3% (CV-AUROC: 39.7%), RF 24.0% (CV-AUROC: 51.7%) and XGBoost 13.3% (CV-AUROC: 52.7%). Anomaly-detection models showed modest but consistent performance across all conditions ( online supplemental table 3 ).
Overall, RF and XGBoost were the best-performing models, particularly under SMOTE and ROSE resampling. Under SMOTE, RF achieved a higher F1-score (84.3% vs 81.5%), while XGBoost showed a higher CV-AUROC (62.7% vs 54.7%). Under ROSE, both models achieved near-identical F1-scores (81.8% vs 81.6%), with XGBoost showing a marginally higher CV-AUROC (69.2% vs 59.6%). EN-LR consistently underperformed in terms of F1-score across all resampling conditions. Undersampling consistently produced the lowest performance across all models ( figure 1 ).
Discussion
This study examined the potential of ML models in identifying VTE risk among COCP users despite low event rates and severe class imbalance. Findings are broadly consistent with recent evidence suggesting ML may offer advantages over traditional scoring systems when synthetic balancing techniques are applied. 21
22 Age, rheumatic and renal diseases, glucocorticoid use, and thyroid disorders were consistently identified as predictive factors that support metabolic and inflammatory contributions to VTE risk—an association reinforced by pooled data from recent artificial intelligence-driven VTE studies. 21
22
Applying data-resampling techniques, including SMOTE and ROSE, improved the model’s ability to learn the characteristics of rare events and to prevent bias from the majority population. The models’ performance increased in terms of the F1-scores, reflecting better minority class detection. Importantly, synthetic oversampling enabled the development of potentially useful predictive models in a low-event real-world setting, demonstrating the feasibility of ML-based pharmacovigilance where traditional methods are limited. The clinical value of this approach lies in the improvement of VTE predictor identification. Using the original imbalanced data, only age at cohort entry and rheumatic diseases were identified as significant predictors. After synthetic data augmentation, a richer set of clinically meaningful predictors was identified, including age at cohort entry, diabetes, glucocorticoid use, renal disease and thyroid disorders, which are biologically plausible and clinically relevant risk factors for VTE. This demonstrates that correcting for class imbalance was not just a technical consideration but directly improved the clinical relevance of the models. However, modest AUROC values alongside high F1 scores raise concern for synthetic sample overfitting, suggesting apparent improvements may not fully reflect true generalisability.
RF and XGBoost consistently outperformed other models under SMOTE and ROSE samples. This is consistent with the findings of previous studies examining the effectiveness of ML models for VTE prediction. 22 – 24 XGBoost was identified as one of the most effective models due to its superior ability at capturing complex non-linear relationships and at modelling high-dimensionality and data imbalance. 23
24 RF, similar to previous studies, demonstrated high classification performance, particularly when oversampling increased the representation of VTE cases, in which the F1-score increased while maintaining an advantage of detailed insights into variable importance. 23
24 However, EN-LR had low predictive performance, even with the aid of synthetic sampling (F1: 2.6%–22.3%). Moreover, although anomaly-detection techniques (ie, one-class SVM and Isolation-Forest) are theoretically suitable for identifying rare events (ie, minority class), both methods performed poorly whether trained on original data or resampled datasets. 25
26 This suggests limited generalisability of such unsupervised methods in this context for clinical prediction purposes.
Our results present several important predictors of VTE among COCP users. Age was among the top predictors, consistent with prior studies. 27 Exposure to glucocorticoids was within the top predictors over the resampled data, indicating that their exposure is a contributor to increased thrombotic risk. 28 Moreover, thyroid, renal and rheumatic disorders appear to have strong predictive power, suggesting the role of the metabolic and endocrine factors in increasing susceptibility to VTE. 29
30 The multifactorial nature of thrombotic risk in COCP users supports incorporating metabolic and inflammatory comorbidities into individualised risk assessments. Notably, all identified predictors are routinely captured in EHRs at the point of COCP prescribing, supporting practical applicability.
A key strength is the use of advanced ML methods addressing the low event rates and class imbalance. However, multiple limitations should be noted. The investigation into the associated factors is retrospective, and consequently some residual confounding may be generated. Moreover, using structured data may lead to misclassification of exposures or outcomes. The synthetic oversampling resulted in imbalanced data and variability, which in turn may lead to problems in generalisation to different clinical populations where baseline risks or clinical characteristics may differ. The elevated F1-scores observed under ROSE and SMOTE (eg, RF F1: 84%) in the context of comparatively lower AUROC values raise concern for synthetic sample overfitting, suggesting that apparent improvements in classification performance may not reflect true generalisability to unseen data. Additionally, all performance metrics were derived from internal validation procedures, and the absence of external validation limits the generalisability of the present findings. Several AUROC values—particularly under imbalanced data and undersampling conditions—approached random discrimination (≈0.50), limiting the confidence in the discriminative ability of these models and underscoring the need for external validation before clinical use. Furthermore, given the predominantly binary nature of the predictor variables in this dataset, standard principal component analysis (PCA) was not considered applicable; future studies with continuous or mixed data may benefit from PCA-based feature validation or dimensionality reduction approaches, as well as post-PCA clustering analyses to identify clinical risk subgroups. Finally, while ML models showed moderate predictive performance, their clinical interpretability and ability to make causal inference remain limited.
This study highlights the potential of ML for VTE risk stratification among COCP users, supporting the value of data-driven approaches in pharmacovigilance. However, external validation in larger and diverse populations is warranted before integration into clinical decision-support tools.
Conclusions
In this study, ML models, particularly XGBoost and RF, demonstrated moderate predictive ability for VTE among COCP users after addressing class imbalance. However, high F1-scores alongside modest AUROC values suggest synthetic sample overfitting, limiting generalisability. These results highlight the potential of RWD and ML for VTE risk stratification and pharmacovigilance, though external validation in larger and diverse populations is warranted before clinical implementation.
Text is read by the "Ask this paper" AI Q&A widget below.
Extraction quality varies by source — PMC NXML preserves structure
cleanly, OA-HTML may include some navigation residue, and OA-PDF can
have broken hyphenation. The publisher copy
(via DOI)
is the canonical version.