Saving Moms with ML: How MLOps Improves Healthcare in Top-Possibility Obstetrics

In the USA, kind of 7 out of each and every 1000 moms be afflicted by each being pregnant and supply issues each and every yr1. Of the ones moms with being pregnant issues, 700 die however 60% of the ones deaths are preventable with the precise scientific consideration, in line with the CDC. Even a few of the 3.7 million a hit births, 19% have both low birthweight or are delivered preterm. Those high-risk pregnancies and deliveries, medically referred to as obstetrics, impose now not just a threat to human lifestyles but in addition a substantial emotional and financial burden on households. A high-risk being pregnant can also be just about 10 occasions costlier than a typical beginning end result, averaging $57,000 for a high-risk being pregnant vs $8,000 for a regular being pregnant2. CareSource, probably the most greatest Medicaid suppliers in the USA, objectives not to best triage those high-risk pregnancies, but in addition spouse with scientific suppliers so they are able to supply lifesaving obstetrics take care of their sufferers earlier than it’s too overdue. Alternatively, there are knowledge bottlenecks that want to be solved.

CareSource wrestled with the problem of now not having the ability to use the whole thing in their ancient knowledge for coaching their gadget studying (ML) fashions. Having the ability to systematically observe ML experiments and cause mannequin refreshes was once additionally a ache level. A lot of these constraints resulted in lengthen in sending time-sensitive obstetrics threat predictions to scientific companions. On this weblog publish, we will be able to in brief speak about how CareSource evolved an ML mannequin to spot high-risk obstetrics after which center of attention on how we constructed a standardized and automatic manufacturing framework to boost up ML mannequin deployment.

Surroundings and Other folks Context

CareSource has a workforce of information scientists and DevOps engineers. Information scientists are accountable for growing ML pipelines while DevOps engineers configure the essential infrastructure to beef up the ML pipelines in manufacturing.

Relating to surroundings setup, CareSource makes use of a unmarried Azure Databricks workspace for dev, staging, and manufacturing. The workforce leverages other Git branches, subsidized via an Azure Repo, to distinguish between environments:

  • dev or characteristic branches: construction
  • major department: staging
  • unencumber department: manufacturing

ML Construction

What sticks out about high-risk obstetrics (HROB) knowledge is that it now not best accommodates fitness profiles but in addition different circumstantial elements, equivalent to financial balance, that can impact the pregnant affected person’s well-being. There are over 500 options altogether and lots of of those clinical-related options are helpful for linked ML fashions, equivalent to re-admission threat mannequin. Therefore, we used Databricks Function Retailer to retailer all wiped clean and engineered options to permit reuse and collaboration throughout tasks and groups.

For more straightforward experimentation with other characteristic combos, we expressed all characteristic variety and imputation strategies within the type of YAML information with out converting the real mannequin coaching code. We first mapped options into other teams in feature_mappings.yml. Then, we defined which characteristic teams to stay or drop in feature_selection_config.yml as proven beneath. The good thing about this method is that we didn’t want to edit mannequin coaching code at once.

# feature_selection_config.yml

  - primary_key_group
  - group_a
  - group_b
  - feature_c
  - feature_d

To permit coaching at scale on a complete set of ancient knowledge, we applied the allotted PySpark framework for knowledge processing. We extensively utilized Hyperopt, an open-sourced instrument that gives Bayesian hyperparameter seek, leveraging effects from previous mannequin configuration runs, to track a PySpark mannequin. With MLflow, all of those hyperparameter trials have been robotically captured. This integrated their hyperparameters, metrics, any arbitrary information (e.g. pictures or characteristic significance information). The usage of MLflow got rid of the handbook fight of keeping an eye on quite a lot of experimentation runs. In keeping with a 2022 perinatal fitness file launched via the Middle for American Growth, we discovered from our initial experimentation that being pregnant threat is certainly a multi-faceted drawback, influenced now not best via fitness historical past but in addition via different socioeconomic determinants.

ML Productionization

Generally, how we productionize fashions has numerous variability throughout tasks and groups even inside the similar group. The similar was once true for CareSource as properly. CareSource struggled with various productionization requirements throughout tasks, slowing down mannequin deployment. Moreover, larger variability approach extra engineering overhead and extra onboarding issues. Therefore, the executive function that we would have liked to reach at CareSource was once to permit a standardized and automatic framework to productionize fashions.

On the center of our workflow is leveraging a templating instrument, Stacks – a Databricks product below non-public preview – to generate standardized and automatic CI/CD workflows for deploying and trying out ML fashions.

Introducing Stacks*

Stacks leverages the deploy-code trend, during which we endorse coaching code, relatively than mannequin artifacts to staging or manufacturing. (You’ll learn extra about deploy-code vs deploy-model on this Large Ebook of MLOps.) It supplies a cookiecutter template to arrange infrastructure-as-code (IaC) and CI/CD pipelines for ML fashions in manufacturing. The usage of cookiecutter activates, we configured the template with Azure Databricks surroundings values equivalent to Databricks workspace URL and Azure garage account title. Stacks, via default, assumes other Databricks workspaces for staging and manufacturing. Subsequently, we custom designed how Azure carrier principals are created, in order that we may have two SPs, i.e. staging-sp and prod-sp, in the similar workspace. Now that we have got the CI/CD pipelines in position, we proceeded with adapting our ML code in line with the cookiecutter template. The diagram beneath displays the whole structure of the ML construction and automatic productionization workflow that we applied.

*Notice: Stacks is a Databricks product below non-public preview and is consistently evolving to make long term mannequin deployments even more straightforward. Keep tuned for the approaching unencumber!

Manufacturing Structure and Workflow

Note: MLflow Model Registry is also used in staging, but not shown in this picture for simplicity.
Notice: MLflow Type Registry could also be utilized in staging, however now not proven on this image for simplicity.

Within the dev surroundings:

  • Information scientists are loose to create any characteristic branches for mannequin construction and exploration
  • They dedicate code in opposition to Git steadily to save lots of any work-in-progress
  • As soon as knowledge scientists determine a candidate mannequin to transport ahead with manufacturing:
    – They additional modularize and parameterize ML code if want be
    – They enforce unit and integration checks
    – They outline paths to retailer MLflow experiments, MLflow fashions, coaching and inference task frequencies
  • Finally, they publish a pull request (PR) in opposition to the staging surroundings, i.e. major department

Within the staging surroundings:

  • The PR triggers a sequence of unit checks and integration checks below the Steady Integration (CI) step outlined in Azure DevOps
    – Examine that the characteristic engineering and mannequin coaching pipelines run effectively and convey effects inside expectation
  • Sign in the candidate mannequin in MLflow Type Registry and transition its level to staging
  • As soon as all checks move, merge the PR into the major department

Within the prod surroundings:

  • Information scientists lower a model of the major department to the unencumber department to push the mannequin to manufacturing
  • A Steady Supply (CD) step in Azure DevOps is prompted
    – Very similar to the staging surroundings, check that the characteristic engineering and mannequin coaching pipelines run effectively
  • As soon as all checks move, sign in the candidate mannequin within the MLflow Type Registry and transition to Manufacturing, if that is the primary mannequin model
    – For long term mannequin model upgrades, the challenger mannequin (model 2) has to exceed a efficiency threshold when in comparison to the present mannequin in manufacturing (model 1), earlier than it transitions to Manufacturing
  • Load the mannequin in MLflow Type Registry and generate batch predictions
    – Persist the ones predictions in Delta tables and behavior any post-processing steps

The standardized workflow describe above can now be carried out to all different ML tasks at CareSource. Every other the most important part that simplifies mannequin control is automation. We don’t wish to cause checks manually when we now have loads of fashions to control. The embedded part inside Stacks that permits automation is Terraform. We expressed all configurations as code, together with compute assets to spin up characteristic engineering, mannequin coaching, and inference jobs. The added bonus from Terraform is that we will now construct and model those infra adjustments as code. Putting in place IaC by the use of Terraform and CI/CD is non-trivial from scratch, however thankfully Stacks supplies each bootstrapping automation and reference CI/CD code out of the field. For example, the usage of the Terraform useful resource beneath,, we scheduled a prod batch inference jobs to run at 11am UTC day by day, whilst pulling code from the unencumber department.
useful resource "databricks_job" "batch_inference_job" {
  title = "${native.env_prefix}-batch-inference-job"

  new_cluster {
    num_workers   = 2
    spark_version = "11.3.x-cpu-ml-scala2.12"
    node_type_id  = "Standard_D3_v2"
    single_user_name   = knowledge.databricks_current_user.service_principal.user_name
    data_security_mode = "SINGLE_USER"

  notebook_task {
    notebook_path = "notebooks/04_batch_inference"
    base_parameters = {
      env = native.env

  git_source {
    url      = var.git_repo_url
    supplier = "azureDevOpsServices"
    department   = "unencumber"

  time table {
    quartz_cron_expression = "0 0 11 * * ?" # day by day at 11am
    timezone_id            = "UTC"

On this task, we additionally leveraged each project-wide and environment-specific configuration information. This enabled simple toggling between other configurations as the surroundings modified from dev to staging, as an example. Normally, parameterized information assist stay our ML pipeline blank and bug-free from parameter iterations:

# configurations/configs.yml 

  data_dir_path: &dir table_path 
  feature_selection_config: feature_selection_config.yml
    split_config: [0.8, 0.2]
      hyperparam_1: 10
      hyperparam_2: 0.01


To recap, we used Databricks Function Retailer, MLflow, and Hyperopt to increase, track, and observe the ML mannequin to expect obstetrics threat. Then, we leveraged Stacks to assist instantiate a production-ready template for deployment and ship prediction effects at a well timed time table to scientific companions. An end-to-end ML framework, entire with manufacturing best possible practices, can also be difficult and time-consuming to enforce. Alternatively, we established the ML construction and productionization structure detailed above inside roughly 6 weeks.

So how did Stacks assist us boost up the productionization procedure at CareSource?


Stacks supplies a standardized and but totally customizable ML task construction, infra-as-code, and CI/CD template. It’s agnostic to how mannequin construction code is written so we had totally flexibility over how we wrote our ML code and which applications we used. The information scientists at CareSource can personal this procedure totally and deploy fashions to manufacturing in a self-service type via following the guardrails Stacks supplies. (As discussed previous, Stacks gets even more straightforward to leverage because it undergoes enhancements right through this non-public preview segment!)

The CareSource workforce can now simply prolong this template to beef up different ML use circumstances. The most important studying from this paintings was once that early collaboration between each the information science and DevOps (ML) engineering groups is instrumental to making sure clean productionization.

Migrating this high-risk obstetrics mannequin to Databricks is best the start for CareSource. The sped up transition between ML construction and productionization now not best allows knowledge practitioners to completely unharness the facility of information and ML, however at Caresource, it approach having a possibility to at once have an effect on sufferers’ fitness and lives earlier than it’s too overdue.

CareSource was once decided on as Some of the Best possible Puts to Paintings 2020 and received the Scientific Innovator Award. If you want to sign up for CareSource to fortify their participants’ well-being, take a look at their profession openings right here.


  1. Blue Go Blue Defend Group – the Well being of The united states. (2020, June 17). Tendencies in Being pregnant and Childbirth Headaches within the U.S. Retrieved March 23, 2023, from
  2. M. Lopez. (2020, August 6). Managing Prices in Top-Possibility Obstetrics. AJMC.

Like this post? Please share to your friends:
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: