In last Post, I have explained the process of creating Event Hub, Stream Analytics, and Azure ML model for the aim of applying machine learning to streamed Data. In this post, I will show how to create a function in Stream Analytics for calling the Azure ML API and finally see the result in the Power BI.
Stream Analytics Function
In this stage, we have created an Event Hub, Application to generate random Number, stream analytics and Azure ML model and API to group the streamed data.
In this section, we need to create a function inside Stream Analytics to be able to call the created API in Azure ML. Click on the Azure Stream Analytics job, then click on the Function.
In the creating function page, select the subscription name, the Key and URL extracted from Excel file.
In-Stream Analytics main page, we need to add some code in Query editor to be able to call the function. Click on Edit Query, then in the editor paste the below code
WITH MLStreamAnalytics AS (
SELECT value, MLStreamAnalytics(value) as result
FROM azureml
)
SELECT
value, result.[value_quantized]
INTO
MLoutput
FROM
MLStreamAnalytics
The first part of the code is for calling the function and get the result from it. As you can see in the below picture, the first part of the code is about the creating a temp table to call the MLStreamAnalytics(value), Then in the next step is about the get the data from Event Hub component (From Azure ML).
The second part of the code about gets the data from a function in azure stream analytics, then pass the data to Power BI component (MLoutput).
Live Analytics on Stream data
The last step is to run the code. First, we need to run the Stream Analytics job by clicking on the Start key.
After running the streaming analytics, open your Power BI service from powerbi.microsoft.com. As you can see below picture, a streamed dataset has been created in Power BI. To work with it click on the report icon and create an empty report.
In the report page, a new Power BI report is shown with on a dataset that has two fields: Value and Value_quantized.
Need to run the code in.Net application and add the report to the new workspace, after running the code and check the workspace, you able to see the live data coming from the application and the streamed data in Power BI beside the group name and number that each Value is allocated using Azure ML model.
In this post and the last one, an overview of what is Azure Stream Analytics is provided, the different components have been explained briefly. The use case shows how we can leverage it for live analytics using Azure ML model and API has been explained. A sample application to generate a random number has been illustrated, then how we can use Event Hub, Stream Analytics, Azure ML, and Power BI together to show a streamed live data analysis.
[1] https://docs.microsoft.com/en-us/sql/advanced-analytics/install/sql-r-services-windows-install
[2] https://radacad.com/stream-analytics-and-power-bi-join-forces-to-real-time-dashboard