How To Build A Linear Regression Web Service In Azure ML Model

In this article, we are going to build a linear regression model. After building the model, we will train it and publish it as a web service so that we can use the service in any application.

What is Liner Regression

We model the relationship between two variables using Linear Regression. A dependent variable is denoted as Y and an independent variable is denoted as X.

Y= b1X+b0

Advertisement will be independent while Sales will be a dependent variable (Predictor). 

Determine Y; X is variable; b1 is slope; b0 intercept

Example: Sales = Some Coefficient * Advertisement + Intercepts 

Requirement

  • Azure ML Account. Using the following link, you can create account https://studio.azureml.net/

We are attaching the college professor salary dataset here.

Solution

  • First, login to the Azure ML portal. You will see the following screen.

    Azure

  • Go to the Dataset and click “New” ( At the bottom of the page).

    Azure
  • Chose the data source or upload the file from local system.

    Azure
  • Chose the file and provide the appropriate data name and click the bottom right button.

    Azure

Now, we have successfully uploaded the dataset.

In our dataset, we know that the Linear Regression is best to evaluate the result set. So, let’s build the model and publish as web service.

Building Experiment

  • Select the Experiment tab from the left navigation and click the “New” to start the experiment.

    Azure

  • Chose a template which fits your requirement. I am choosing the blank template as highlighted in the screen print.

    Azure
  • You will get the page like below, click on the highlighted part to name your experiment.

    Azure
  • Select the Data source (which you uploaded in the first part in this article), drag the data source into the first box.

    Azure
  • Once you drop your data source your page will look like this .

    Azure
  • Select the data column from the data set. Go to Data, Transform Manipulation and Select Columns in the Data set; and drag and drop below to your data set.

    Azure
  • Connect the data set to the “Select Columns in Data set”. You can see the red dot in your “Select Columns in Data set” because you didn’t select it. Select the column. Click Right Side “Launch Column Selector” (Number 1) from your right side , the window will popup  and select the column. Once you are done with the selection click the bottom on the bottom  right side on popup windows

    Azure
  • Now split the data set into the Training and Test data set and choose the ratio. For that
    go to Left Navigation, Data Transformation, Sample and Split, and Split Data (Drag and drop to below of “Select Columns In Dataset”). And in the right side you can choose the fraction of rows. We can chose 80% Training and 20% as Test data.

    Azure
  • Now, import data to training data. For that Go To Left Navigation, Train, and Train Model. Drag this to below the Split Data section. And click the Lunch Column Selector and select the column which will be your depend variables. In our case it's Salary

    Azure

  • Now it's time to select the algorithm. Based on that, we initially finalize if we will be using the Linear Regression to evaluate or not.

    Azure
  • Add the Source model and link with training Model and Split data sources

    Azure

  • Finally now add the Evaluate model task in your experiment project and run it

    Azure

  • Now it's time to test the model, at the bottom of the page you will get the Run button click on that and run the test the model.

    Azure
  • After successfully running, let’s visualize the outcome. Select the "Evaluate Model" and right click on Visualization.

    Azure

Your output

Azure

Setup the web service in this model

  • At bottom of the model, you will get a button called “SET UP WEB SERVICE[Recommended]”. Click on that and it will convert to web service. In this process, some of the steps will be merged and create a new one.

    Azure

    Model will look like,

    Azure
  • Now, web service has been created but we need to modify two things to get the desired result.

    • Web service input will be attached to the model, not to our data set because, in web service, the user will provide the input.

      Model will look like this,

      Azure

    • In select Column in dataset we need to remove the “Salary“column because the Salary will be the out so it will not be as input.

      Select the “Select Column in Dataset “click on right side “Lunch Column Selector”

      Remove the salary and click the bottom right button.

      And Run the model to test.

      Azure
  • Now, let's deploy our web service. Before deploying, run the model to test.

    At the bottom of the page, you will see the "Deploy" button. Click it so as to deploy your web service.

    Azure

Once the Deployment is completed, you will see the following screen.

Azure

  • Now, it is time to test your model.

    Click "Test" and provide the input.

    Azure

Input the data and click on OK button.
Azure

Result will look like this.

Azure

Click on the New Web Service Experience and it will bring you the Web Service page.

Azure

Output

Azure

You can test the End Point, Configuration etc.. 

I have provided detailed steps here. If you still have any question and concerns, do comment below. 


Similar Articles