Machine Learning for Predicting Cervical Cancer: A Random Forest Approach Using Combined Nigerian and Public Datasets
Abstract
Cervical cancer remains a leading cause of cancer related mortality among women in low and middle-income countries, where screening and vaccination rates are low. This paper presents a Random Forest machine learning model for predicting cervical cancer risk using a combined dataset of 908 patients from the Federal Teaching Hospital Lokoja (FTHL), Nigeria (50 records) and the UCI Cervical Cancer Risk Factors repository (858 records). The model was trained on 11 attributes including age, HPV status, sexual history, smoking, hormonal contraceptive use, and reproductive factors. Hyperparameter tuning via grid search with cross validation which yielded optimal parameters (mtry=3, ntree=226, min_n=6) with a cross validated accuracy of 0.966. On the test set, the model achieved 97.4% accuracy, 98.2% precision, 99.1% sensitivity, 98.6% F1 score, and an AUC of 0.901. Permutation feature importance identified HPV status (mean importance = 0.238) and hormonal contraceptive use (mean importance = 0.125) as the most significant predictors. The high sensitivity is particularly valuable for clinical applications, ensuring that nearly all cancer cases are detected. The integration of FTHL and UCI datasets enhanced model generalizability by exposing it to diverse patient populations. However, validation revealed that pooled performance was substantially driven by data source confounding, with leave-one-cohort-out AUC falling to 0.53–0.70 and within-FTHL AUC of 0.39, highlighting the need for careful interpretation and prospective validation.