Friday, March 03, 2023

Deploy the Azure Machine Learning Model

In the previous post I have discussed how to create an Azure Machine Model.  In this post I will be discussing how to Deploy this model.

Prerequisites

Before deploying a machine learning model in Azure, there are several prerequisites you need to fulfill:

Prepare your data: You should have a well-prepared and cleaned dataset that has been tested and validated.

Select your model: You need to choose an appropriate machine learning algorithm based on your problem statement and the nature of your data.

Train your model: You need to train your machine learning model on your prepared dataset.

As you must have seen we have undertaken all these steps and have trained our model in Azure Machine Learning in the previous post.


As part of training the model, we have created an inference pipeline.  Now if we want to deploy the model, we need to create a real time inference pipeline.

In order to do that, in the Azure Portal launch the Azure Machine Learning studio as shown below.




Monday, February 27, 2023

Create a Predictive Model in Azure Machine Learning -- Designer mode

Today after a long time, I wanted to play around with Azure Machine Learning Designer formerly Machine Learning Studio.  

So I set our to create a Predictive Model using the Sample data that is available in Azure ML -- Automobile price data (Raw)

So I logged in to Azure Portal -- 


Creating a Machine Learning Workspace

The first step is to create a Machine Learning Resource -- 

So for that Click on Create a Resource Button and search machine learning as shown below:



Click on Azure Machine Learning

The below screen appears. 


Click on Create.  The below screen appears.



Fill in the Resource Group, Workspace Name and Region details.

Fill in other details in the other tabs if needed and click on Review and Create

Now the Azure Machine Learning Workspace is created as below



Click on the Name of the AML workspace

The below screen appears.




Click on Launch Studio.  This will launch the Azure Machine Learning (AML) interface.

Click on the Create New -- This opens up the Menu of what can be created as shown below.


Ingesting Data

Click on Pipeline.  This will create a New Pipeline Menu as shown below




As you can see it uses the Designer Authoring tool.  Now Click on the Plus button which is Create a pipeline using classic pre-built components.

This will open a blank canvas in the designer as shown below:





Now we are ready to create a training model.  Click on the two arrows beside Undo as shown in the above image.  This will open a Menu which contains the components that can be used to build the predictive model as shown below:


Click on Sample data and drag the dataset named Automobile Price Data (Raw) on to the blank canvas




You can right-click the Automobile price data (Raw) component and select Preview Data to understand the dataset. 

Each row corresponds to an automobile, and the variables associated with each automobile appear as columns. There are 205 rows and 26 columns in this dataset.



Preparing Data


Now that we have chosen the dataset we need to clean the data. 
First step in preparing data is to eliminate columns that we do not need 
Second step is to remove the missing values.  

So if you look at the dataset carefully, there are many values missing from the column normalized-losses.  So we need to eliminate this column.  To achieve this, we can use the Select Column in dataset component as shown below.


Now connect the Dataset component with the Select Columns component.




Double click on the New component and choose Edit Columns and create the rules as below to Include All columns Except the column named  normalized-losses



Next step is to remove other missing values.  For this we will use the Clean missing data component.  Drag this component to the Canvas.  Connect the Select columns dataset component to the Clean missing data component as shown below.

Double Click on the Clean missing data component and change as shown below.



Preparing Training and test data
Now that we have prepared and cleaned the dataset, the next step is to prepare the train and test data,  For this we will use Split Data component.  Search for the Split Data component and drag it to the canvas.  Connect the Clean Missing data component to the Split Data component.  Make sure that the Cleaned dataset port is connected as shown below.





Double click the Split Data component and configure as shown below. The 0.7 in the Fraction of rows in the first output dataset. means that the dataset will be split into 70% and 30%.  The 70% dataset will be used for training a model and 30% dataset can be used as a test dataset.



Training a Model
The Next Step is to train a model.  From the data we are going to Predict the Price of the automobile.  So we will use a linear regression model.  So Search for the Linear Regression component and drag it to the canvas.  Next search for a Train Model and drag it to the canvas.  And connect these components as shown below.



Scoring and Evaluating the Model

Next add the components -- Score Model and Evaluate Model on to the canvas and connect them as shown below:



Now your Pipeline is ready.  

Next Steps --- 
In order to train this model, you need to click on the Submit button



Once you submit you will be prompted with the below configuration.



Ensure that you have configured the Compute Target as well as shown below





This will create a pipeline job and a notification will pop up at the top right corner of the page.   Since this is your first job, this might take up to 20 mins to run.  Once you get the notification that the job is completed, you can look at the job detail page as shown below.



You can then look at the scored labels and price predicted as shown below.



You can use the Evaluate Model to see how well the trained model performed on the test dataset as shown below



You can see the error statistics above.  For each of the error statistics, smaller is better. A smaller value indicates that the predictions are closer to the actual values. 

For the coefficient of determination, the closer its value is to one (1.0), the better the predictions.


That's it from me for today.

In my next blog post I will show you how you can deploy this model.




































Tuesday, November 22, 2022

Create a Lollipop Chart in Power BI -- Without the use of any Custom Visuals

 I have been playing around with the newly launched Error Bars functionality in Power BI.  The result is this Blog Post.  Here I am going to explain how you can create a lollipop chart in Power BI without using any custom visuals or charticulator or deneb 

Step 1:  

Create a simple line chart -- I have sales data and region data.  So I created a line chart as shown below.



Step 2:  

Format the line chart to remove the line as shown below.  Click on the format icon -- Visual tab -- Line -- Stroke Width -- Change from 3 px to 0


The result of this action is -- the line will entirely disappear as we changed the Stroke Width from 3 px to 0 px.




Step 3:  

Add Markers as shown below and ensure that the shape is a circle resembling the ball of the lollipop and increase the size to 10 px to get reasonable sized balls



The result is as shown below.


Step 4:  
Ensure that the Data Labels are Enabled and choose Position as Above as shown below
You can disable Y-Axis if you need to.  



Step 5:  
Here is where we will be using the Error Bars to add the Line to show the lollipop stick.
To go to the Error Bars section -- Go to the Further Analytics icon and click on Error Bars.
Enable the Error Bars.  As shown below it needs an Upper Bound and Lower Bound.  Upper Bound can be Sum of Sales and the Lower Bound is always 0 (Zero).  Since there is no way to input a number, let us create a Measure that returns 0 .  
The new Measure is -- Lowerbound = 0
 

Step 6:
You can see faint lollipop lines.  You can increase the width of the line by clicking on the Bar and changing the Width as shown below


And Viola!  Your Lollipop chart is ready!

Hope you liked this Step by Step instruction on creating the lollipop chart.












Tuesday, June 28, 2022

Default your Date Slicer to Today with this trick!

 Today I had a requirement from a client to Default the Date Slicer to Today.

I explored different options as to how I can do it -- Like using the Filter Pane  -- but this will filter the entire visual or page.  So this was not an option.


So I thought of creating a new column named Actual Date in my Date table.  So I created as below.


The formula I used was an IF statement,  

Actual Date = IF('Date'[Date]=TODAY(),"Today",'Date'[Date])

But this resulted in an error.  When you closely look at the formula I have written, you may notice that the output is in two data types..  One is a Text data type which is Today and the other one is a Date which is a Date data type.


So I have now modified the formula as below to convert the date data type into a text data type.  Then the error is gone.

Actual Date = IF('Date'[Date]=TODAY(),"Today",'Date'[Date]&"")

Basically what the If statement is doing is -- If the Date is equal to Today's date then the text Today is going to be populated in the Actual Date column, otherwise the date is going to be populated as shown below.


Once you create the new column, create a slicer with the new column (Actual Date) and sort the data by descending and choose Today to default the slicer value.  

After this is done, you will notice that the slicer is always defaulted to Today.


You can follow a similar approach for Month as well.  








Thursday, August 12, 2021

Free Excel Classes for Adults Week 2

Yesterday was week 2 of free Microsoft Excel classes.  In the beginner class of week 1 there were both kids and adults. Strongly felt the need to separate the kids and adults classes.  So yesterday's class was restricted only to adults.

Thank you Bharatiya Mandir for this wonderful opportunity.  The topics covered in this 2 hour session are as below:

  • Working with multiple worksheets
  • Text and Date Functions
  • Functions for Summarising Data
  • Pivot Tables

Again enjoyed interacting with everyone.  

Thanks to Krina and Harshavardhan for all your help in running this class.

Here a few glimpses from the session.







Friday, August 06, 2021

Day 4 of #30daysofML Learning

Below is my learning for Day 4 of #30daysofML

The datatype for boolean in python is 'bool'

Boolean operators are used for comparison

3.0 == 3

'3'== 3

Comparison operators can be combined with the arithmetic operators 

Remember to use == instead of = when making comparisons.

Booleans are most useful when combined with conditional statements like if then else statement

Python has a functions as below:

  • int() function  which turns things into ints, 
  • float() functon which turns things into floats, 
  • bool() function which turns things into bools.
  • Calling bool() on an integer returns False if it’s equal to 0 and True otherwise. 
  • int(True) is 1, and int(False) is 0.

We can use non-boolean objects in if conditions and other places where a boolean would be expected. Python will implicitly treat them as their corresponding boolean value:

Here is the order of precedence of operators in Python


Operator

Description

(expressions...),

[expressions...]{key: value...}{expressions...}

Binding or parenthesized expression, list display, dictionary display, set display

x[index]x[index:index]x(arguments...)x.attribute

Subscription, slicing, call, attribute reference

await x

Await expression

**

Exponentiation 5

+x-x~x

Positive, negative, bitwise NOT

*@///%

Multiplication, matrix multiplication, division, floor division, remainder 6

+-

Addition and subtraction

<<>>

Shifts

&

Bitwise AND

^

Bitwise XOR

|

Bitwise OR

innot inisis not<<=>>=!===

Comparisons, including membership tests and identity tests

not x

Boolean NOT

and

Boolean AND

or

Boolean OR

if – else

Conditional expression

lambda

Lambda expression

:=

Assignment expression


Thursday, August 05, 2021

Free Excel Classes week 1

Yesterday I have started free Microsoft Excel classes for the people in the community who were interested.  There was a good turn out of around 30 people.  Thank you Bharatiya Mandir for this wonderful opportunity.

Thoroughly enjoyed interacting with everyone.  Thanks to Krina. Smriti, Medha and Harshavardhan for all your help in running this class.

Here a few glimpses from the session.











Day 3 of #30daysofML from Kaggle

Below is my learning for today as part of Day 3 of #30daysofML


help()

help(round)

help(round(-30.18)

help(print)


Defining functions

Builtin functions are great, but we can only get so far with them before we need to start defining our own functions. 

Example if we want to calculate the least difference between 3 numbers

def least_diff (num1, num2, num3):

diff1 =num1-num2

diff2 =num2-num3

diff3 =num3-num1

return min(diff1, diff2, diff3)

Functions start with a header introduced by the def keyword. The indented block of code following the : is run when the function is called.

return is another keyword uniquely associated with functions. When Python encounters a return statement, it exits the function immediately, and passes the value on the right hand side to the calling context.

If there is no return in the function, then the function will not return anything.

But there are some functions with no return statements inside them.  Examples are print() and help()

Python allows trailing commas in argument lists. How nice is that?


Deploy the Azure Machine Learning Model

In the previous post I have discussed how to create an Azure Machine Model.  In this post I will be discussing how to Deploy this model. Pre...