Table of Contents
- Introduction
- Medicine Demand Prediction Copilot: Leveraging Azure Machine Learning for Time Series Forecasting
- Introduction
- Overall Flow:
- Technologies Used:
- Step-by-Step Guide to Building the Medicine Demand Prediction Copilot
- Step 1: Create the CSV with the Medicine Demand History
- Step 2: Create the Azure ML Model
- Step 3: Deploy the Model as an Endpoint
- Step 4: Creating the Copilot in Copilot Studio
- Step 5: Enable Generative Selection of Topics
- Step 6: Create Topics
- Step 7: Add Adaptive Card for User Inputs
- Step 8: Invoke Azure ML Endpoint
- Step 9: Display Prediction Results
- Test the Copilot
- Conclusion
Introduction
Medicine Demand Prediction Copilot: Leveraging Azure Machine Learning for Time Series Forecasting
Introduction
In the pharmaceutical industry, accurate demand forecasting is essential for maintaining a stable supply chain and avoiding medicine shortages or overstocking. To address this, businesses can use the power of Microsoft Copilot integrated with Azure Machine Learning to predict the future demand for medicines based on historical data. By leveraging time series forecasting, we can predict the quantity of medicines that will be required in the coming months. This enables companies to make informed decisions about procurement, ensuring the right medicines are available when needed while optimizing costs.
The Medicine Demand Prediction Copilot is designed to automate this forecasting process. By passing relevant data, such as Date, Medicine Name, Manufacturer, Price Per Unit, and Discount, to an Azure Machine Learning endpoint, the copilot predicts the Quantity Sold for the next month. This prediction can be used by procurement teams to plan medicine purchases more effectively.
Overall Flow:
- Data Input: The user inputs historical data, including fields like Date, Medicine Name, Manufacturer, Price Per Unit, and Discount.
- Invoke Azure Machine Learning Endpoint: The copilot sends this data to a pre-configured Azure Machine Learning time series forecasting endpoint.
- Predict Quantity Sold: The Azure ML model analyzes the historical data and returns a forecast of the Quantity Sold for each medicine for the upcoming month.
- Display Predictions: The copilot displays the predicted quantity of medicines required, helping the user make data-driven decisions for procurement.
- Procurement Decision: Based on the predicted demand, the procurement team can place orders for the required medicines in advance, optimizing inventory and reducing waste.
Technologies Used:
- Microsoft Copilot: A powerful tool used to interact with users and facilitate the flow of information between different services, including machine learning models.
- Azure Machine Learning (Time Series Forecasting): A machine learning service that provides time series forecasting models to predict the future demand for medicines based on historical data.
- CSV: For storing and retrieving historical medicine sales data that will be used to train the Azure ML.
Step-by-Step Guide to Building the Medicine Demand Prediction Copilot
Step 1: Create the CSV with the Medicine Demand History
For this demo, we will be using CSV file which contains the below 7 year medical information from 2018-2024 and will use it to create a Time Series Forecasting Azure ML model which we will consume from Copilot.
- Date
- MedicineName
- Manufacturer
- QuantitySold
- PricePerUnit
- Discount
Step 2: Create the Azure ML Model
-
Head over to the Azure Portal and search and click on Azure Machine Learning.
-
From Create, select New Workspace.
-
Specify the details of the new machine learning workspace by entering the resource group, name, and region where the workspace has to be hosted. Click on Create to provision the resource.
-
Once the resource is successfully provisioned either select the Launch studio option or head over to Azure ML Studio to access Azure Machine Learning Studio.
-
This will take us to the Azure ML Studio where we will be provisioning the time series model.
-
Select Automated ML and click on New Automated ML job.
-
Specify the Job and Experiment name and click on Next.
-
Select the Task Type as Time Series forecasting and click on Create which will allow us to add the training data set.
-
In this page, specify the dataset name and set the dataset type as Tabular. Click on Next.
-
We can use the dataset from Azure Storage or SQL Databases or even upload a local file. In our demo, we will go ahead and upload the CSV file which contains historic medicine data. Click on Next.
-
We can select the storage where the uploaded dataset will be stored. We will go ahead with Azure Blob Storage. Azure Data Lake Storage Gen 2 is another option. Click on Next.
-
Now click on Upload files and browse the CSV file and upload the training data.
-
Once successfully uploaded, click on Next.
-
The uploaded dataset is now available for review. Click on Next.
-
If we want to make changes to the datatype or format, we can do that. We will leave the defaults and click on Next.
-
Click on Create to finalize and create the dataset.
-
Select the created dataset and click on Next to proceed with the model creation.
-
Since we are going to predict the Quantity of medicine sold, we will select the Target column as QuantitySold. We will be using the date column in the CSV as the Time column which will hold the timestamp for the time series data.
-
We will uncheck the Autodetect forecast horizon option and set the value as 14. We will also add ExtremeRandomTrees in the blocked models so that it won’t be used for training. Click on Save.
-
We will also enable early termination of the training if the scores do not improve over time. Set the number of cross-validations as 5 and click on Next.
-
To run the training job, we need compute resources for which we will select the compute type as Compute cluster and click on New to add the compute resource.
-
We will select Dedicated Virtual Machine Tier and CPU as the Virtual Machine type. For this demo, we are using Standard_DS12_V2 Configuration, click on Next.
-
Specify the compute name and click on Create.
-
The compute cluster is now provisioned. Click on Next.
-
Click on Submit Training Job to start the model training with the uploaded training data. This will take upwards of 1 hour based on the amount of training data we have.
-
After some time, we can see that the model training is completed. Click on the algorithm name present in the Best Summary model section.
Step 3: Deploy the Model as an Endpoint
-
We will now deploy this model as an endpoint, for which we will select Webservice from the Deploy menu.
-
Specify the Endpoint name and select Azure Container Instance as the Compute Type. Click on Deploy.
-
Once the endpoint is provisioned, we can view it from the Endpoints section. The REST endpoint URL is the endpoint that we can use for invoking a POST request from Copilot. Copy this URL.
Step 4: Creating the Copilot in Copilot Studio
-
Head over to Copilot Studio and click on Create.
-
This will provide us the option to create a copilot based on an existing template or create a blank copilot from scratch. Let’s select New Copilot.
-
This will take us to the page where we can:
- Describe the copilot functionality and provide any specific instructions to the copilot.
- Once done, click on Create to provision the copilot.
Step 5: Enable Generative Selection of Topics
- The copilot is now created. We can then make the needed configuration changes.
- Click on Edit, edit the copilot details like name, icon, and description.
- Click on Settings to enable the Generative selection of topics so that without relying on triggers, the topics will be auto-selected based on user conversation, resulting in a much smoother user experience.
- To enable the automatic detection of topics from user interaction:
- Click on Generative AI.
- Select Generative (preview).
- Select High – More precise for Content Moderation.
- Click on Save to update the settings.
- Click on the Close icon to go back to the homepage of this custom copilot.
Step 6: Create Topics
- Now let’s go ahead and create the topics that will automatically redirect the conversation flow to appropriate topics based on the question the user posts.
- Click on Topics from the navigation menu.
- Click on Topics from the navigation menu.
- To add the topic, we can either go with the option to create a blank topic or use Copilot to create the topic with an initial set of prepopulated conversation nodes based on the topic description that we provide.
- Let’s click on Add a Topic and
- Select Create from description with Copilot.
- Let’s provide the below topic description details in the popup that opened when we clicked the Add Topic button previously. Then, click on Create, which will provision the topic skeleton based on the provided description.
Step 7: Add Adaptive Card for User Inputs
- Thus we have the basic topic created with an automatic trigger as well as a question to the user which are generated using the description provided. We can now add more conversation nodes.
- As the first step, let’s add an Adaptive Card to accept details from the user.
- As the first step, let’s add an Adaptive Card to accept details from the user.
-
Add the below Adaptive Card schema which will accept the Date, MedicineName, Manufacturer, PricePerUnit, and Discount from the user.
-
The output of the adaptive card will contain the user-inputted values in respective variables, which can be passed on to the Azure ML model.
- We want to format the input date as dd-MM-YYYY format which is what the Azure ML model will expect. To do this, let’s add a Variable action and use PowerFx expression to format the date using the below expression.
Step 8: Invoke Azure ML Endpoint
-
As the next step, let’s add an HTTP Action which will invoke the Azure ML time series forecasting model endpoint and pass the user-entered inputs as parameters to this POST request.
-
Specify the Azure ML endpoint URL that we copied from Azure ML Studio into the URL field. Set the method as POST and click on Edit to add the header and body.
-
Click on Add and specify the Key-Value pair as Content-Type and application/json respectively. Set the Body dropdown as JSON Content.
-
Since we will be passing dynamic values entered by the user, select Formula from the dropdown so that we can use Power Fx expressions and reference the adaptive card variables.
-
Add the below schema to the text box which will be the body sent to the Azure ML endpoint.
-
Now let’s define the output variable as PredictionResults and set the response data type as From sample data. Click on Get Schema from sample JSON to provide the sample output from the Azure ML endpoint, using which it will auto-create the response schema.
-
Add the sample output and click on Confirm.
Step 9: Display Prediction Results
- We will add a Basic Card and extract the predicted demand using the below expression and show it in the card.
Thus we have completed the configuration of the Copilot Studio that invokes the Azure ML Time Series Forecasting endpoint to predict medicine demand.
Test the Copilot
Now let’s test the Copilot and input the details for checking the demand for the medicine Morphease for October 2024.
The input values are passed to the Azure ML endpoint, and we have generated the demand prediction results for the medicine.
Conclusion
The Medicine Demand Prediction Copilot leverages Azure Machine Learning and Copilot Studio to automate the forecasting process for medicine demand. This provides procurement teams with the insights they need to make informed decisions about medicine purchases, ensuring that stock levels are optimized while minimizing the risk of shortages or overstocking. By integrating data input, machine learning prediction, and real-time results into a seamless flow, this solution supports the pharmaceutical industry in maintaining an efficient supply chain.