Published on InterSystems Developer Community (https://community.intersystems.com)

主页 > 部分IRIS 2022 年度编程大奖赛作品展示—— 利用IRIS 一体化机器学习IntegratedML来预测糖尿病的Web 应用

文章
Michael Lei · 六月 1, 2022 阅读大约需 6 分钟
Open Exchange

部分IRIS 2022 年度编程大奖赛作品展示—— 利用IRIS 一体化机器学习IntegratedML来预测糖尿病的Web 应用

糖尿病可以从医学界熟知的一些参数中发现。这样,为了帮助医学界和计算机软件系统,特别是人工智能软件,美国国家糖尿病和消化道及肾脏疾病研究所发布了一个非常有用的数据集,用于训练糖尿病检测/预测的机器学习算法。这份出版物可以在最大和最知名的ML数据库Kaggle上找到,网址是https://www.kaggle.com/datasets/mathchi/diabetes-data-set。

该糖尿病数据集有以下元数据信息(来源:https://www.kaggle.com/datasets/mathchi/diabetes-data-set):

  • 怀孕:怀孕次数
  • 葡萄糖: 口服葡萄糖耐量试验中2小时的血浆葡萄糖浓度 Plasma glucose concentration a 2 hours in an oral glucose tolerance test
  • 血压: 舒张压(mm Hg)
  • 皮肤厚度:  肱三头肌皮褶厚度(mm)
  • 胰岛素: 2小时血清胰岛素(mu U/ml)
  • BMI: 体重指数 (体重 kg/(身高 m)^2)
  • 糖尿病血统函数: 糖尿病血统函数(它提供了一些关于亲属中的糖尿病史以及这些亲属与病人的遗传关系的数据。这种对遗传影响的测量使我们了解到一个人可能有的遗传风险与糖尿病的发病有关--来源:https://machinelearningmastery.com/case-study-predicting-the-onset-of-di...)
  • 年龄:
  • 结果: 类变量 (0 or 1)

实例数量: 768

属性数量: 8 + 1个类变量

对每个属性: (全部为numeric数字量化类型)

  1. 怀孕次数
  2. 口服葡萄糖耐量试验中2小时的血浆葡萄糖浓度  
  3. 舒张压 (mm Hg)
  4. 三头肌皮褶厚度 (mm)
  5. 2小时血清胰岛素 (mu U/ml)
  6. BMI指数 (体重 kg/(身高 m)^2)
  7. 糖尿病血统函数
  8. 年龄
  9. 类变量 (0 or 1)

缺失属性值: 是

类分布: (类值为1解释为 "糖尿病测试阳性")

从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"?>
<Export generator="Cache" version="25">
  <Document name="predict-diseases.ZPM">
    <Module>
      <Name>predict-diseases</Name>
      <Version>1.0.0</Version>
      <Packaging>module</Packaging>
      <SourcesRoot>src/iris</SourcesRoot>
      <Resource Name="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>

预测糖尿病的前端和后端应用程序

访问 Open Exchange  应用连接 (https://openexchange.intersystems.com/package/Disease-Predictor) 并遵守以下步骤:

  1. Clone/git 把repo pull 到任何本地目录
$ git clone https://github.com/yurimarx/predict-diseases.git
  1. 打开 该目录下Docker终端并执行:
$ docker-compose build
  1. 执行IRIS container:
$ docker-compose up -d 
  1. 在管理门户中执行查询来训练AI模型: http://localhost:52773/csp/sys/exp/%25CSP.UI.Portal.SQL.Home.zen?$NAMESPACE=USER
  2. 创建用来训练的 VIEW :
CREATE VIEW DiabetesTrain AS SELECT Outcome, age, bloodpressure, bmi, diabetespedigree, glucose, insulin, pregnancies, skinthickness FROM dc_data_health.Diabetes
  1. 利用View视图来创建 AI 模型:
CREATE MODEL DiabetesModel PREDICTING (Outcome) FROM DiabetesTrain
  1. 训练模型:
TRAIN MODEL DiabetesModel
  1. 访问 http://localhost:52773/disease-predictor/index.html 来使用疾病预测器qian frontend and predict diseases like this: Disease-Predictor

幕后工作

后端预测糖尿病的类方法

InterSystems IRIS 支持执行Select 并使用上一个创建的模型来预测。

 
Backend ClassMethod to predict Diabetes
/// Predict Diabetes
ClassMethod PredictDiabetes() As %Status
{
    Try {
      Set data = {}.%FromJSON(%request.Content)
     
      Set qry = "SELECT PREDICT(DiabetesModel) As PredictedDiabetes, "
                  _"age, bloodpressure, bmi, diabetespedigree, glucose, insulin, "
                  _"pregnancies, skinthickness "
                  _"FROM (SELECT "_data.age_" AS age, "
                  _data.bloodpressure_" As bloodpressure, "
                  _data.bmi_" AS bmi, "
                  _data.diabetespedigree_" AS diabetespedigree, "
                  _data.glucose_" As glucose, "
                  _data.insulin_" AS insulin, "
                  _data.pregnancies_" As pregnancies, "
                  _data.skinthickness_" AS skinthickness)"
      Set tStatement = ##class(%SQL.Statement).%New()
      Set qStatus = tStatement.%Prepare(qry)
      If qStatus'=1 {WRITE "%Prepare failed:" DO $System.Status.DisplayError(qStatus) QUIT}
      Set rset = tStatement.%Execute()
      Do rset.%Next()
 
      Set Response = {}
      Set Response.PredictedDiabetes = rset.PredictedDiabetes
      Set Response.age = rset.age
      Set Response.bloodpressure = rset.bloodpressure
      Set Response.bmi = rset.bmi
      Set Response.diabetespedigree = rset.diabetespedigree
      Set Response.glucose = rset.glucose
      Set Response.insulin = rset.insulin
      Set Response.pregnancies = rset.pregnancies
      Set Response.skinthickness = rset.skinthickness
 
      Set %response.Status = 200
      Set %response.Headers("Access-Control-Allow-Origin")="*"
     
      Write Response.%ToJSON()
     
      Return 1
     
    } Catch err {
      write !, "Error name: ", ?20, err.Name,
          !, "Error code: ", ?20, err.Code,
          !, "Error location: ", ?20, err.Location,
          !, "Additional data: ", ?20, err.Data, !
      Return 0
    }
}

现在,任何网络应用都可以使用预测并显示预测结果。欢迎在frontend 文件夹查看本应用的源代码。

#Artificial Intelligence (AI) #IntegratedML #InterSystems IRIS
在 InterSystems Open Exchange 上检查相关应用程序

源 URL:https://cn.community.intersystems.com/post/%E9%83%A8%E5%88%86iris-2022-%E5%B9%B4%E5%BA%A6%E7%BC%96%E7%A8%8B%E5%A4%A7%E5%A5%96%E8%B5%9B%E4%BD%9C%E5%93%81%E5%B1%95%E7%A4%BA%E2%80%94%E2%80%94-%E5%88%A9%E7%94%A8iris-%E4%B8%80%E4%BD%93%E5%8C%96%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0integratedml%E6%9D%A5%E9%A2%84%E6%B5%8B%E7%B3%96%E5%B0%BF%E7%97%85%E7%9A%84web-%E5%BA%94%E7%94%A8