Using natural language processing and machine learning to identify social needs in patient medical notes: model training with balanced versus real-world datasets.
Christopher Kitchen, Thomas Richards, Luis M Ahumada, Geoffrey M Gray, Ayah Zirikly, Elham Hatef
{"title":"Using natural language processing and machine learning to identify social needs in patient medical notes: model training with balanced versus real-world datasets.","authors":"Christopher Kitchen, Thomas Richards, Luis M Ahumada, Geoffrey M Gray, Ayah Zirikly, Elham Hatef","doi":"10.1093/jamiaopen/ooag170","DOIUrl":null,"url":null,"abstract":"<p><strong>Objective: </strong>To evaluate natural language processing (NLP) and machine learning (ML) approaches for identifying social needs in electronic health record (EHR) notes, using balanced versus real-world imbalanced datasets.</p><p><strong>Materials and methods: </strong>A rule-based NLP framework using definite, non-negated keywords flagged social needs domains and \"Any Social Need\" in unstructured notes. Logistic regression, random forest, and XGBoost models were trained under balanced and imbalanced prevalence and evaluated using area under the receiver operating characteristic curve (AUROC), area under the precision-recall curve (AUPRC), F1, precision, recall, and specificity, with threshold sensitivity analyses.</p><p><strong>Results: </strong>On the imbalanced test set for any social need, the rule-based model achieved F1 0.373 (precision 0.484; recall 0.303; and specificity 0.978). On the balanced test set for any social need, XGBoost and logistic models achieved AUPRC 0.719 and 0.718, F1 0.438, and precision 0.944; random forest had AUPRC 0.714, F1 0.423, and precision 0.945. Under imbalanced evaluation, XGBoost led (AUPRC 0.319, F1 0.312, precision 0.839, recall 0.191, and specificity 0.998), followed by logistic (AUPRC 0.312 and F1 0.289) and random forest (AUPRC 0.305 and F1 0.282).</p><p><strong>Discussion: </strong>Balanced training inflated apparent performance, while under realistic class imbalance the ML models traded recall for very high precision, with XGBoost performing best but still lagging in sensitivity.</p><p><strong>Conclusion: </strong>These findings underscore the need to train and tune under real-world prevalence and to set thresholds based on use-case priorities (eg, maximizing precision for referrals versus improving recall for screening).</p>","PeriodicalId":36278,"journal":{"name":"JAMIA Open","volume":"9 4","pages":"ooag170"},"PeriodicalIF":4.7000,"publicationDate":"2026-08-17","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC13480434/pdf/","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"JAMIA Open","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1093/jamiaopen/ooag170","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"2026/8/1 0:00:00","PubModel":"eCollection","JCR":"Q2","JCRName":"HEALTH CARE SCIENCES & SERVICES","Score":null,"Total":0}
引用次数: 0
Abstract
Objective: To evaluate natural language processing (NLP) and machine learning (ML) approaches for identifying social needs in electronic health record (EHR) notes, using balanced versus real-world imbalanced datasets.
Materials and methods: A rule-based NLP framework using definite, non-negated keywords flagged social needs domains and "Any Social Need" in unstructured notes. Logistic regression, random forest, and XGBoost models were trained under balanced and imbalanced prevalence and evaluated using area under the receiver operating characteristic curve (AUROC), area under the precision-recall curve (AUPRC), F1, precision, recall, and specificity, with threshold sensitivity analyses.
Results: On the imbalanced test set for any social need, the rule-based model achieved F1 0.373 (precision 0.484; recall 0.303; and specificity 0.978). On the balanced test set for any social need, XGBoost and logistic models achieved AUPRC 0.719 and 0.718, F1 0.438, and precision 0.944; random forest had AUPRC 0.714, F1 0.423, and precision 0.945. Under imbalanced evaluation, XGBoost led (AUPRC 0.319, F1 0.312, precision 0.839, recall 0.191, and specificity 0.998), followed by logistic (AUPRC 0.312 and F1 0.289) and random forest (AUPRC 0.305 and F1 0.282).
Discussion: Balanced training inflated apparent performance, while under realistic class imbalance the ML models traded recall for very high precision, with XGBoost performing best but still lagging in sensitivity.
Conclusion: These findings underscore the need to train and tune under real-world prevalence and to set thresholds based on use-case priorities (eg, maximizing precision for referrals versus improving recall for screening).
目的:评估自然语言处理(NLP)和机器学习(ML)方法在电子健康记录(EHR)笔记中识别社会需求的作用,使用平衡与现实世界的不平衡数据集。材料和方法:一个基于规则的NLP框架,在非结构化笔记中使用明确的、非否定的关键词标记社会需求域和“任何社会需求”。在平衡和不平衡患病率下训练Logistic回归、随机森林和XGBoost模型,并使用受试者工作特征曲线下面积(AUROC)、精确召回曲线下面积(AUPRC)、F1、精度、召回率和特异性进行评估,并进行阈值敏感性分析。结果:在任意社会需求的不平衡测试集上,基于规则的模型达到F1 0.373(精度0.484,召回率0.303,特异性0.978)。在任意社会需求的平衡测试集上,XGBoost和logistic模型的AUPRC分别为0.719和0.718,F1为0.438,precision为0.944;随机森林的AUPRC为0.714,F1为0.423,精度为0.945。在不平衡评价下,XGBoost领先(AUPRC 0.319, F1 0.312,精密度0.839,召回率0.191,特异性0.998),其次是logistic (AUPRC 0.312, F1 0.289)和随机森林(AUPRC 0.305, F1 0.282)。讨论:平衡训练夸大了明显的性能,而在现实的类别不平衡下,ML模型用召回率换取了非常高的精度,XGBoost表现最好,但灵敏度仍然落后。结论:这些发现强调了在现实世界的流行情况下进行培训和调整的必要性,以及基于用例优先级设置阈值的必要性(例如,最大限度地提高转诊的准确性,而不是提高筛查的召回率)。