Predicting Freight cost of Shipment of Medications across different Vendors

Contents

  1. Introdution
  2. Preparing CSV
  3. Using End point
    • 3.1 Creating model
    • 3.2 Creating Endpoint Config
    • 3.3 Creating Endpoint
    • 3.4 Invoking Endpoint
    • 3.5. Deleting the Endpoint - Optional
  4. Model Output

1. Introdution

  • The supply chain is one of a provider’s largest cost centers, and represents one of the most significant opportunities for healthcare organizations to trim unnecessary spending and improve efficiency.

  • Predictive tools are in high demand among hospital executives looking to reduce variation and gain more actionable insights into ordering patterns and supply utilization.

  • Only 17 percent of hospitals currently use automated or data-driven solutions to manage their supply chains, said Cardinal Health in 2017.

  • In the same year, Global Healthcare Exchange ranked predictive analytics for supply chain management as the number one item on the executive wish list – a follow-up survey in 2018 found that adopting data analytics tools remained a top priority.

  • Using analytics tools to monitor the supply chain and make proactive, data-driven decisions about spending could save hospitals almost $10 million per year, a separate Navigant survey added. Both descriptive and predictive analytics can support decisions to negotiate pricing, reduce the variation in supplies, and optimizing the ordering process.

2. Preparing CSV

The csv file used in the model contains 13 columns,

  • fulfill_via
  • shipment_mode
  • sub_classification
  • unit_of_measure_per_pack
  • pack_price
  • unit_price
  • manufacturing_site
  • first_line_designation
  • weight_kilograms
  • line_item_insurance_usd
  • Waiting_Time_days
  • delivered_to_client_date_M
  • delivery_recorded_date_M

Same kind of CSV file should be fed to the model for best output.

For reference, A sample CSV file is attached in the link. The user only needs to clik on the link to get it downloaded to the local. The data should be in a similar format like the sample csv.

Download sample Data from the link : Data Source for Freight Cost Prediction

In [ ]:
import pandas as pd
df = pd.read_csv('S3/Sagemaker path of FreightCostPrediction.csv file')
df.to_csv("sample.csv",index=False)
df.head(3)

3. Using Endpoint

The model can be directly accessed via the console provided by AWS. However, for a more customized process one can access the model using the below code as well.

3.1 Creating Model

To create a model, import boto3, sagemaker and get the arn of the model package

In [ ]:
import boto3
import sagemaker
role = sagemaker.get_execution_role()
smmp = boto3.client('sagemakermp')
modelName='Name of the model'
modelArn = 'Model ARN name'
createHeatIndexResponse = smmp.create_model(ModelName=modelName,\
                             Containers=[{'ModelPackageName': modelArn}],\
                             ExecutionRoleArn=role,\
                             EnableNetworkIsolation=True )

3.2 Creating Endpoint Config

In [ ]:
configName ='<Input Configuration Name>'
instanceType = '<Input Instance Type>'
createHeatIndexEndpointConfig = smmp.create_endpoint_config(EndpointConfigName = configName, ProductionVariants = [{'InstanceType':instanceType, 'InitialInstanceCount':1, 'ModelName':modelName, 'VariantName':'xyz'}])

3.3 Creating Endpoint

In [ ]:
endpointName = '<Input Endpoint Name>'
createHeatIndexEndpoint = smmp.create_endpoint(EndpointName = endpointName, EndpointConfigName = configName)

3.4 Invoking Endpoint

In [ ]:
runtime = boto3.Session().client('runtime.sagemaker')

#Reading Input Data 
with open('sample.csv','rb') as f:
    payload = f.read()

response = runtime.invoke_endpoint(EndpointName = endpointName, ContentType = 'text/csv', Body = payload)
result = response['Body'].read().decode()

#Writing Output Data 
with open('sampleOutput.txt','w') as f:
    f.write(result)

3.5. Deleting the Endpoint - Optional

If you're ready to be done with this notebook, please run the delete_endpoint line in the cell below. This will remove the hosted endpoint you created and avoid any charges from a stray instance being left on

In [ ]:
sagemaker.Session().delete_endpoint(endpointName)

4. Model Output

In [ ]:
with open("./sampleOutput.txt","r") as f:
    sampleResponse =f.read()
    sampleResponse = sampleResponse.split('\n')
sampleResponse
In [ ]: