8 Machine Learning – Regression Model Using Designer Studio

Azure ML Designer – Regression model

Reference: https://learn.microsoft.com/en-us/training/

Train a linear regression model that predicts car prices using the Azure Machine Learning designer.

Create the pipeline

 Note

Designer supports two type of components, classic prebuilt components and custom components. These two types of components are not compatible.

Classic prebuilt components provides prebuilt components majorly for data processing and traditional machine learning tasks like regression and classification. This type of component continues to be supported but will not have any new components added.

Custom components allow you to provide your own code as a component. It supports sharing across workspaces and seamless authoring across Studio, CLI, and SDK interfaces.

This article applies to classic prebuilt components.

  1. Sign in to ml.azure.com, and select the workspace you want to work with.
  2. Select Designer-> Classic prebuilt

  1. Select Create a new pipeline using classic prebuilt components.
  2. Click the pencil icon beside the automatically generated pipeline draft name, rename it to Automobile price prediction. The name doesn’t need to be unique.

 

Import data

There are several sample datasets included in the designer for you to experiment with. For this tutorial, use Automobile price data (Raw).

  1. To the left of the pipeline canvas is a palette of datasets and components. Select Component-> Sample data.
  2. Select the dataset Automobile price data (Raw), and drag it onto the canvas.

Visualize the data

You can visualize the data to understand the dataset that you’ll use.

  1. Right-click the Automobile price data (Raw)and select Preview Data.
  2. Select the different columns in the data window to view information about each one.

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

Prepare data

Datasets typically require some preprocessing before analysis. You might have noticed some missing values when you inspected the dataset. These missing values must be cleaned so that the model can analyze the data correctly.

Remove a column

When you train a model, you have to do something about the data that’s missing. In this dataset, the normalized-losses column is missing many values, so you’ll exclude that column from the model altogether.

  1. In the datasets and component palette to the left of the canvas, click Componentand search for the Select Columns in Dataset component.
  2. Drag the Select Columns in Datasetcomponent onto the canvas. Drop the component below the dataset component.
  3. Connect the Automobile price data (Raw)dataset to the Select Columns in Dataset component. Drag from the dataset’s output port, which is the small circle at the bottom of the dataset on the canvas, to the input port of Select Columns in Dataset, which is the small circle at the top of the component.

 

You create a flow of data through your pipeline when you connect the output port of one component to an input port of another.

  1. Select the Select Columns in Datasetcomponent.
  2. Click on the arrow icon under Settings to the right of the canvas to open the component details pane. Alternatively, you can double-click the Select Columns in Datasetcomponent to open the details pane.
  3. Select Edit columnto the right of the pane.
  4. Expand the Column namesdrop down next to Include, and select All columns.
  5. Select the +to add a new rule.
  6. From the drop-down menus, select Excludeand Column names.
  7. Enter normalized-lossesin the text box.
  8. In the lower right, select Saveto close the column selector.

  1. In the Select Columns in Datasetcomponent details pane, expand Node info.
  2. Select the Commenttext box and enter Exclude normalized losses.

Comments will appear on the graph to help you organize your pipeline.

Clean missing data

Your dataset still has missing values after you remove the normalized-losses column. You can remove the remaining missing data by using the Clean Missing Data component.

 In the datasets and component palette to the left of the canvas, click Component and search for the Clean Missing Data component.

  1. Drag the Clean Missing Datacomponent to the pipeline canvas. Connect it to the Select Columns in Dataset component.
  2. Select the Clean Missing Datacomponent.
  3. Click on the arrow icon under Settings to the right of the canvas to open the component details pane. Alternatively, you can double-click the Clean Missing Datacomponent to open the details pane.
  4. Select Edit columnto the right of the pane.
  5. In the Columns to be cleanedwindow that appears, expand the drop-down menu next to Include. Select, All columns
  6. Select Save
  7. In the Clean Missing Datacomponent details pane, under Cleaning mode, select Remove entire row.
  8. In the Clean Missing Datacomponent details pane, expand Node info.
  9. Select the Commenttext box and enter Remove missing value rows.

Your pipeline should now look something like this:

Train a machine learning model

Now that you have the components in place to process the data, you can set up the training components.

Because you want to predict price, which is a number, you can use a regression algorithm. For this example, you use a linear regression model.

Split the data

Splitting data is a common task in machine learning. You’ll split your data into two separate datasets. One dataset trains the model and the other will test how well the model performed.

  1. In the datasets and component palette to the left of the canvas, click Componentand search for the Split Data component.
  2. Drag the Split Datacomponent to the pipeline canvas.
  3. Connect the left port of the Clean Missing Datacomponent to the Split Data component.

 Important

Make sure that the left output port of Clean Missing Data connects to Split Data. The left port contains the cleaned data. The right port contains the discarded data.

  1. Select the Split Datacomponent.
  2. Click on the arrow icon under Settings to the right of the canvas to open the component details pane. Alternatively, you can double-click the Split Datacomponent to open the details pane.
  3. In the Split Datadetails pane, set the Fraction of rows in the first output dataset to 0.7.

This option splits 70 percent of the data to train the model and 30 percent for testing it. The 70 percent dataset will be accessible through the left output port. The remaining data is available through the right output port.

  1. In the Split Datadetails pane, expand Node info.
  2. Select the Commenttext box and enter Split the dataset into training set (0.7) and test set (0.3).

Train the model

Train the model by giving it a dataset that includes the price. The algorithm constructs a model that explains the relationship between the features and the price as presented by the training data.

  1. In the datasets and component palette to the left of the canvas, click Componentand search for the Linear Regression component.
  2. Drag the Linear Regressioncomponent to the pipeline canvas.
  3. In the datasets and component palette to the left of the canvas, click Componentand search for the Train Model component.
  4. Drag the Train Modelcomponent to the pipeline canvas.
  5. Connect the output of the Linear Regressioncomponent to the left input of the Train Model component.
  6. Connect the training data output (left port) of the Split Datacomponent to the right input of the Train Model component.

 Important

Make sure that the left output port of Split Data connects to Train Model. The left port contains the training set. The right port contains the test set.

  1. Select the Train Modelcomponent.
  2. Click on the arrow icon under Settings to the right of the canvas to open the component details pane. Alternatively, you can double-click the Train Modelcomponent to open the details pane.
  3. Select Edit columnto the right of the pane.
  4. In the Label columnwindow that appears, expand the drop-down menu and select Column names.
  5. In the text box, enter priceto specify the value that your model is going to predict.

Your pipeline should look like this:

Add the Score Model component

After you train your model by using 70 percent of the data, you can use it to score the other 30 percent to see how well your model functions.

  1. In the datasets and component palette to the left of the canvas, click Componentand search for the Score Model component.
  2. Drag the Score Modelcomponent to the pipeline canvas.
  3. Connect the output of the Train Modelcomponent to the left input port of Score Model. Connect the test data output (right port) of the Split Data component to the right input port of Score Model.

Add the Evaluate Model component

Use the Evaluate Model component to evaluate how well your model scored the test dataset.

  1. In the datasets and component palette to the left of the canvas, click Componentand search for the Evaluate Model component.
  2. Drag the Evaluate Modelcomponent to the pipeline canvas.
  3. Connect the output of the Score Modelcomponent to the left input of Evaluate Model.

The final pipeline should look something like this:

Submit pipeline

  1. Select Configure & Submiton the right top corner to submit the pipeline.

  1. Then you’ll see a step-by-step wizard, follow the wizard to submit the pipeline job.

In Basics step, you can configure the experiment, job display name, job description etc.

In Inputs & Outputs step, you can assign value to the Inputs/Outputs that are promoted to pipeline level. In this example it will be empty because we didn’t promote any input/output to pipeline level.

In Runtime settings, you can configure the default datastore and default compute to the pipeline. It’s the default datastore/compute to all components in the pipeline. However, if you set a different compute or datastore for a component explicitly, the system respects the component level setting. Otherwise, it uses the default.

The Review + Submit step is the last step to review all settings before submit. The wizard will remember your last configuration if you ever submit the pipeline.

After submitting the pipeline job, there will be a message on the top with a link to the job detail. You can select this link to review the job details.

View scored labels

In the job detail page, you can check the pipeline job status, results and logs.

After the job completes, you can view the results of the pipeline job. First, look at the predictions generated by the regression model.

  1. Right-click the Score Modelcomponent, and select Preview data > Scored dataset to view its output.

Here you can see the predicted prices and the actual prices from the testing data.

 

Evaluate models

Use the Evaluate Model to see how well the trained model performed on the test dataset.

  1. Right-click the Evaluate Modelcomponent and select Preview data > Evaluation results to view its output.

The following statistics are shown for your model:

  • Mean Absolute Error (MAE): The average of absolute errors. An error is the difference between the predicted value and the actual value.
  • Root Mean Squared Error (RMSE): The square root of the average of squared errors of predictions made on the test dataset.
  • Relative Absolute Error: The average of absolute errors relative to the absolute difference between actual values and the average of all actual values.
  • Relative Squared Error: The average of squared errors relative to the squared difference between the actual values and the average of all actual values.
  • Coefficient of Determination: Also known as the R squared value, this statistical metric indicates how well a model fits the data.

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.

 

License

Icon for the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Data Visualization Insights - Hands-on Book Copyright © 2023 by Saint Peter's University is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book