文章 Frank Ma · 六月 13, 2022 6m read

使用IRIS IntegratedML(一体化机器学习)预测孕产妇风险的Web应用

孕产妇风险可以通过一些医学界众所周知的参数来测量。这样,为了帮助医学界和计算机系统,特别是人工智能,科学家Yasir Hussein Shakir发布了一个非常有用的数据集,用于训练检测/预测孕产妇风险的机器学习(ML)算法。这份出版物可以在最大和最知名的ML数据库Kaggle上找到,网址是 https://www.kaggle.com/code/yasserhessein/classification-maternal-healt….

关于数据集

由于缺乏怀孕期间和怀孕后的孕产妇保健信息,许多孕妇死于怀孕问题。这在农村地区和新兴国家的中下层家庭中更为常见。在怀孕期间,应时刻注意观察,以确保婴儿的正常成长和安全分娩 (来源: https://www.kaggle.com/code/yasserhessein/classification-maternal-healt…).

数据是通过基于物联网的风险监测系统,从不同的医院、社区诊所、孕产妇保健机构收集而来。

  • Age(年龄): 妇女怀孕时的年龄,以岁为单位。
  • SystolicBP (收缩压): 血压的最高值(mmHg),这是怀孕期间的另一个重要属性。
  • DiastolicBP(舒张压): 血压的较低值(mmHg),这是怀孕期间的另一个重要属性。
  • BS(血糖): 血糖水平是以摩尔浓度为单位,即mmol/L。
  • HeartRate(心率): 正常的静息心率,单位是每分钟的心跳次数。
  • Risk Level(风险等级): 基于前边的属性所预测的孕期风险强度水平。

从Kaggle获取孕产妇的风险数据

来自Kaggle的孕产妇风险数据可以通过Health-Dataset(健康数据集)应用程序加载到IRIS表中: https://openexchange.intersystems.com/package/Health-Dataset. 要做到这一点,在你的module.xml项目中,设置依赖关系(Health Dataset的ModuleReference):

 

Module.xml with Health Dataset application reference

<?xml version="1.0" encoding="UTF-8"?>
<Exportgenerator="Cache"version="25">
  <Documentname="predict-diseases.ZPM">
    <Module>
      <Name>predict-diseases</Name>
      <Version>1.0.0</Version>
      <Packaging>module</Packaging>
      <SourcesRoot>src/iris</SourcesRoot>
      <ResourceName="dc.predict.disease.PKG"/>
      <Dependencies>
        <ModuleReference>
          <Name>swagger-ui</Name>
          <Version>1.*.*</Version>
        </ModuleReference>
        <ModuleReference>
          <Name>dataset-health</Name>
          <Version>*</Version>
        </ModuleReference>
      </Dependencies>
       <CSPApplication
        Url="/predict-diseases"
        DispatchClass="dc.predict.disease.PredictDiseaseRESTApp"
        MatchRoles=":{$dbrole}"
        PasswordAuthEnabled="1"
        UnauthenticatedEnabled="1"
        Recurse="1"
        UseCookies="2"
        CookiePath="/predict-diseases"
       />
       <CSPApplication
        CookiePath="/disease-predictor/"
        DefaultTimeout="900"
        SourcePath="/src/csp"
        DeployPath="${cspdir}/csp/${namespace}/"
        MatchRoles=":{$dbrole}"
        PasswordAuthEnabled="0"
        Recurse="1"
        ServeFiles="1"
        ServeFilesTimeout="3600"
        UnauthenticatedEnabled="1"
        Url="/disease-predictor"
        UseSessionCookie="2"
      />
    </Module>
   
  </Document>
</Export>

Web Frontend and Backend Application to Predict Maternal Risk

Go to Open Exchange  app link (https://openexchange.intersystems.com/package/Disease-Predictor) and follow these steps:

  1. 使用Clone/git 把repo拉到任一本地目录中:
$ git clone https://github.com/yurimarx/predict-diseases.git
  1. 在该文件夹中打开Docker 终端并运行:
$ docker-compose build
  1. 运行IRIS容器:
$ docker-compose up -d 
  1. 进入管理门户执行查询,训练AI模型: http://localhost:52773/csp/sys/exp/%25CSP.UI.Portal.SQL.Home.zen?$NAMESPACE=USER
  2. 创建用于训练的VIEW(视图):
CREATE VIEW MaternalRiskTrain AS SELECT BS, BodyTemp, DiastolicBP, HeartRate, RiskLevel, SystolicBP, age FROM dc_data_health.MaternalHealthRisk 
  1. 使用视图创建AI模型:
CREATE MODEL MaternalRiskModel PREDICTING (RiskLevel) FROM MaternalRiskTrain 
  1. 训练模型:
TRAIN MODEL MaternalRiskModel
  1. 访问 http://localhost:52773/disease-predictor/index.html ,使用 Disease Predictor(疾病预测器)前端进行疾病预测,如下: Maternal-Risk-Predictor

幕后工作

预测孕产妇风险疾病的后端类方法

InterSystems IRIS允许你执行SELECT,使用之前创建的模型进行预测。

 

Backend ClassMethod to predict Maternal Risk

///Predict Maternal Risk
ClassMethodPredictMaternalRisk()As%Status
{
    Try{
      Setdata={}.%FromJSON(%request.Content)
      Set%response.Status=200
      Set%response.Headers("Access-Control-Allow-Origin")="*"
     
      Setqry="SELECT PREDICT(MaternalRiskModel) As PredictedMaternalRisk, "
                  _"age, BS, BodyTemp, DiastolicBP, HeartRate, SystolicBP "
                  _"FROM (SELECT "_data.BS_" AS BS, "
                  _data.BodyTemp_" As BodyTemp, "
                  _data.DiastolicBP_" AS DiastolicBP, "
                  _data.HeartRate_" AS HeartRate, "
                  _data.SystolicBP_" As SystolicBP, "
                  _data.Age_" AS age)"
      SettStatement=##class(%SQL.Statement).%New()
      SetqStatus=tStatement.%Prepare(qry)
      IfqStatus'=1{WRITE"%Prepare failed:"DO$System.Status.DisplayError(qStatus)QUIT}
      Setrset=tStatement.%Execute()
      Dorset.%Next()

 

      SetResponse={}
      SetResponse.PredictedMaternalRisk=rset.PredictedMaternalRisk
      SetResponse.Age=rset.Age
      SetResponse.SystolicBP=rset.SystolicBP
      SetResponse.DiastolicBP=rset.DiastolicBP
      SetResponse.BS=rset.BS
      SetResponse.BodyTemp=rset.BodyTemp
      SetResponse.HeartRate=rset.HeartRate

 

      WriteResponse.%ToJSON()
      Return1
     
    }Catcherr{
      write!,"Error name: ",?20,err.Name,
          !,"Error code: ",?20,err.Code,
          !,"Error location: ",?20,err.Location,
          !,"Additional data: ",?20,err.Data,!
      Return0
    }
}

现在,任何web应用都可以进行预测并显示结果。请在预测疾病应用程序的前端文件夹中查看源代码。