MLonFHIR: Fusing Sklearn with the HL7 FHIR Standard

栏目: IT技术 · 发布时间: 6年前

内容简介:Read more about internals and extendability in theThere are two general ways of searching for patients with specific properties. The first one is to search by coding system:The second one is by text. The searched tags are CodeableConcept.text, Coding.displ

ml-on-fhir

A work in progress library that fuses the HL7 FHIR standard with scikit-learn

Read more about internals and extendability in the readthedocs .

Usage (taken from our demo notebook )

First: Register the base URL of your database with a FHIRCient object:

from fhir_client import FHIRClient
import logging
import pandas as pd

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

client = FHIRClient(service_base_url='https://r3.smarthealthit.org', logger=logger)

Querying Patients

There are two general ways of searching for patients with specific properties. The first one is to search by coding system:

# To receive a list of available procedures:
procedures = client.get_all_procedures()
pd.DataFrame([prod.code['coding'][0] for prod in procedures]).drop_duplicates().sort_values(by=['display']).head()

# Now retrieve patients
patients_by_procedure_code = client.get_patients_by_procedure_code("http://snomed.info/sct","73761001")

The second one is by text. The searched tags are CodeableConcept.text, Coding.display, or Identifier.type.text:

conditions = client.get_all_conditions()
pd.DataFrame([cond.code['coding'][0] for cond in conditions]).drop_duplicates(subset=['display']).sort_values(by='display', ascending=True).head()

patients_by_condition_text = client.get_patients_by_condition_text("Abdominal pain")

One can also load a control group for a specific cohort of patients. The control group is of equal size of the case cohort (min size: 10) and is composed of randomly sampled patients that do not match the original query. Their class is contained in the .case property of the Patient object.

patients_by_condition_text_with_controls = client.get_patients_by_condition_text("Abdominal pain", controls=True)

print("{} are cases and {} are controls".format(len([d for d in patients_by_condition_text_with_controls if d.case]), 
                                                len([d for d in patients_by_condition_text_with_controls if not d.case])))

Machine Learning

To train a classifier, we need to first tell the MLOnFHIRClassifier the type of object which we would like to classify. We can then define features ( feature_attrs ) and labels ( label_attrs ) for our classification task and pass the preprocessor of our current client, so it is clear how to preprocess the features/labels of a patient. We can then simply call .fit on the MLOnFHIRClassifier instance together with our classifier of choice.

from ml_on_fhir import MLOnFHIRClassifier
from fhir_objects.patient import Patient
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score, roc_curve, auc

ml_fhir = MLOnFHIRClassifier(Patient, feature_attrs=['birthDate', 'gender'],
                             label_attrs=['case'], preprocessor=client.preprocessor)
X, y, trained_clf = ml_fhir.fit(patients_by_condition_text_with_controls, DecisionTreeClassifier())

from sklearn.metrics import accuracy_score, roc_curve, auc
fpr, tpr, _ = roc_curve(y, trained_clf.predict(X))
print("Prediction accuracy {}".format( auc(fpr, tpr) ) )

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

数据挖掘

数据挖掘

(美)Jiawei Han、(加)Micheline Kamber、(加)Jian Pei / 范明、孟小峰 / 机械工业出版社 / 2012-8 / 79.00元

数据挖掘领域最具里程碑意义的经典著作 完整全面阐述该领域的重要知识和技术创新 这是一本数据挖掘和知识发现的优秀教材,结构合理、条理清晰。本书既保留了相当篇幅讲述数据挖掘的基本概念和方法,又增加了若干章节介绍数据挖掘领域最新的技术和发展,因此既适合初学者学习又适合专业人员和实践者参考。本书视角广阔、资料翔实、内容全面,能够为有意深入研究相关技术的读者提供足够的参考和支持。总之, 强烈推荐......一起来看看 《数据挖掘》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

随机密码生成器
随机密码生成器

多种字符组合密码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具