Azure empowers you with the most advanced machine learning capabilities to quickly and easily build, train, and deploy your machine learning models using Azure Machine Learning (Azure ML). Power BI lets you visually explore and analyze your data. In this post we will see how we have made it easy to use the power of Azure ML in Power BI. Once you build your models in Azure ML and deploy them as Web-services, then in just a few clicks you can use them in Power BI to make predictions on your data.
Azure ML Studio is a fully-managed cloud service that enables you to easily build, deploy, and share predictive analytics solutions. To start off sign up and login to Azure ML Studio. For this blog we simply used one of the out of the box samples. The sample builds a binary classification model to predict if the income levels of adult individuals would be greater or less than $50,000. You can learn more about the sample here. After running the Predictive Experiment from the sample we deploy the model as web-service using the “Deploy Web Service [New] Preview” option. “Classic” web service option is not supported in Power BI.
In the next page you will asked to give your web-service a name and select a Price plan. The “Standard DevTest” plan is not supported so make sure to use one of the other “Standard” plans.
Note: Power BI optimizes the number of requests sent to your web-service by sending batches of your data to the web-service. The number of transactions to your web-service originating from Power BI will be much lower than your data size (number of rows).
Azure Machine Learning service provides SDKs and services to quickly prep data, train, and deploy machine learning models. You can find all the documentation regarding Azure ML services here. You can follow the steps outlined here to create a web-service. In the scoring python script we must specify the schema the web-service expects using the inference_schema.schema_decorators from the azureml python SDK. This step is mandatory for the Web-service to the discovered in Power BI as an AI Function.
Here is the sample scoring python script used in our sample.
import json import pickle import numpy as np import pandas as pd import azureml.train.automl from sklearn.externals import joblib from azureml.core.model import Model from inference_schema.schema_decorators import input_schema, output_schema from inference_schema.parameter_types.numpy_parameter_type import NumpyParameterType from inference_schema.parameter_types.pandas_parameter_type import PandasParameterType def init(): global model model_path = Model.get_model_path('linearregmodel') # deserialize the model file back into a sklearn model model = joblib.load(model_path) input_sample = pd.DataFrame(data=[{ "age": 39, "workclass": "State-gov", "fnlwgt": 77516, "education": "Bachelors", "education-num": 13, "martial-status": "Never-Married", "occupation": "Adm-clerical", "relationship": "Not-in-family", "race": "White", "sex": "Male", "capital-gain": 2174, "capital-loss": 0, "hours-per-week": 40, "native-country": "Cuba" }]) output_sample = pd.DataFrame(data=[{ "Scored Labels": "<=50", "Scored Probabilities": 0.20 }]) @input_schema('data', PandasParameterType(input_sample)) @output_schema('data', PandasParameterType(output_sample)) def run(data): try: result = model.predict(data) # you can return any datatype as long as it is JSON-serializable return result.tolist() except Exception as e: error = str(e) return error
In order for other users to use the web-service in Power BI you must to share it with them. Sharing is done through Role Based Access Control in the Azure portal. You can find the steps to do that here.
Now for the easy part! With your web-services deployed you can login to your Power BI account and start using it in your dataflows!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.