Explore data and train models
- 12/27/2024
- Skill 2.1: Explore data by using data assets and datastores
- Skill 2.2: Create models by using the Azure Machine Learning Designer
- Skill 2.3: Use automated machine learning to explore optimal models
Skill 2.2: Create models by using the Azure Machine Learning Designer
The Azure Machine Learning Designer enables you to create models for use in a training pipeline. In order to do this, we need to also be able to consume data assets such as training, validation, and test data in the Designer. These data assets can be used in the training pipeline, with inputs and outputs defined between steps. In this skill, you will develop the techniques and knowledge necessary to start building end-to-end data science solutions in Azure.
Create a training pipeline
A training pipeline in Azure Machine Learning Designer is a sequence of steps to prepare data, train a model, and evaluate its performance. It provides a visual and modular approach to building machine learning workflows. We will first log in to the Azure portal, create a new Azure workspace, compute resources, and then design a pipeline:
Log in to the Azure portal and create a new Azure Machine Learning workspace with the necessary configurations.
Create compute resources.
Navigate to the Compute page in Azure Machine Learning Studio and set up a compute cluster for training your model.
Design Your Pipeline:
Go to the Designer page and create a new pipeline (see Figure 2-3).
FIGURE 2.3 Creating a new pipeline
Drag and drop modules onto the canvas to define your workflow, including data preprocessing, model training, and evaluation steps.
Configure and Run.
Set up the properties for each module, such as selecting the algorithm for the Train Model module and defining the evaluation metrics in the Evaluate Model module.
Submit the pipeline as an experiment and monitor its progress. Once the experiment is complete, examine the output of the Evaluate Model module to assess the performance of your trained model.
Consume data assets from the Designer
Data assets are important components of a training pipeline. They include datasets, data transformations, and data connections that are used throughout the pipeline to train and evaluate the model. You can use the Data page in Azure Machine Learning Studio to create new datasets or import existing ones. Supported data sources include web files, datastores, and local files.
Preprocessing data for model training
In the following steps, we will utilize modules to clean and transform data. Next, we will configure these modules to handle missing values and employ other modules to split data and eventually connect the final preprocessed data to our Train Model module for training. Here is a more detailed set of instructions you can follow on your own:
Utilize modules in Azure Machine Learning Studio such as Select Columns in Dataset and Normalize Data to clean and transform your data before training. The modules are in the module panel on the left side of the workspace, organized under category headings.
Configure these modules to select relevant features, handle missing values, and scale numerical data.
Employ the Split Data module to divide your dataset into training and validation sets.
Connect your preprocessed and split datasets to the Train Model module.
Ensure that the data flows correctly through the pipeline to provide the model with the necessary input for training.
Data assets form the backbone of a training pipeline in Azure Machine Learning Designer.
Proper management and utilization of these assets, from creation to preprocessing and splitting, are key to building an effective machine learning model.
Use custom code components in Designer
While Azure Machine Learning Designer provides a wide range of built-in modules, you may encounter scenarios where custom processing is required. Custom code components allow you to integrate Python or R scripts into your pipeline to perform specialized tasks.
Incorporating custom code
One way to use custom code in an Azure Machine Learning training pipeline is via a script. You can develop a Python or R script that performs the desired data processing or analysis task. For example, you might write a script to perform a unique data transformation or to generate custom features. More specifically, you can use the Execute Python Script module (see Figure 2-4). In the following steps, you will use an Execute Python Script module to upload your script and configure it. The configuration will involve both input and output ports. You can integrate this script module with the rest of your pipeline by connecting an output of a previous module with the input of this module, and the output of your script module with subsequent modules.
Add the Execute Python Script module to your pipeline in the Designer.
Upload your script to the module and configure any necessary input and output ports.
Connect the output of a previous module (e.g., data preprocessing) to the input of the Execute Python Script module.
Ensure that the output of your custom script is connected to subsequent modules for further processing or model training.
FIGURE 2.4 Using a custom Python script in Azure ML Designer
Notice that steps 3 and 4 are necessary to integrate your Python Script module with the rest of the pipeline, connecting output of the previous modules (which could itself be another data preprocessing step) to the input of your custom Python Script module (see Figure 2-5). Remember to connect the output of your custom module to the input of the next or subsequent module as well. It might seem obvious, but this is a subtle step because you can form DAGs (directed acyclic graphs) by connecting your module as inputs to many subsequent modules. The concept of a DAG is used when building pipelines that can have many parallel steps and can, for example, fan out. In addition to the fan-out pattern, a DAG can be used as a powerful abstraction for building sequential steps—steps that fan in or converge and manage parallelism and dependencies in your pipeline.
Run your pipeline to test the custom code component and, if necessary, iteratively refine it. Make any necessary adjustments to ensure that it performs as expected within the context of your workflow. Figure 2-5 shows how to connect inputs and outputs using a Python Script module.
FIGURE 2.5 Connecting inputs and outputs in Python Script modules in the Designer
Carefully configure each module in your pipeline. Double-check the parameters and settings to ensure they are appropriate for your data and the problem you’re solving.
Verify that all modules are correctly connected in the pipeline. The output of one module should correctly feed into the input of the next. In the next section, we will look at a more robust procedure for evaluating the model and using responsible AI guidelines.
Evaluate the model, including responsible AI guidelines
Model evaluation is a critical step in the training pipeline. It helps you assess the performance of your model and ensure that it aligns with Responsible AI principles. Our first step is to understand how to evaluate the model using evaluation metrics.
Evaluation metrics
There is a module called the Evaluate Model. You can add this module to your pipeline after the training and scoring steps. This module provides various metrics such as accuracy, precision, recall, and F1 score to assess the performance of your classification model.
What does Evaluate Model do, and why should we use it? We can analyze the results of our models by examining the output of the Evaluate Model module to understand how well your model is performing.
Responsible AI considerations
Microsoft developed a standard called the Responsible AI Standard. This is a framework for building AI systems according to six principles:
Model fairness
Reliability and safety
Privacy and security
Inclusiveness
Transparency
Accountability
We can look at some of these principles in more detail and how we can practice the guidelines when designing our data science solutions in Azure by incorporating specific modules into our pipeline. Figure 2-6 illustrates the relationship between the responsible AI guidelines.
FIGURE 2.6 Pillars of the Responsible AI Guidelines from Microsoft
Fairness
When evaluating your model’s predictions, it’s important to integrate the fairness guideline to assess fairness across different demographic groups. This module helps detect any disparities and allows you to address them effectively, ensuring that your model maintains equity and avoids perpetuating biases. Considering demographic factors such as race or gender in prediction assessment provides valuable insights into potential biases, enabling proactive steps to mitigate them. This approach promotes inclusivity and fairness, which are fundamental principles in AI development and deployment.
Analyzing predictions through a demographic lens offers a deeper understanding of your model’s performance. It helps uncover and rectify any underlying biases within your data or algorithm, ultimately leading to more just and reliable outcomes. Incorporating fairness into your evaluation process allows you to enhance the credibility and reliability of your model while promoting social responsibility in AI development. This approach increases the trust in your model’s outputs but also contributes to creating a more equitable landscape in the applications where it’s utilized.
Explainability
When exploring your model’s predictions, using the Model Interpretability module provides insights into how the model makes decisions. This tool helps you understand the factors influencing these decisions, fostering transparency in the process. Transparency is key for stakeholders to grasp how the model reaches its conclusions, building trust and facilitating informed decision-making.
However, it’s important to distinguish between model interpretability and fairness assessment. While interpretability focuses on understanding the model’s decision-making process, fairness evaluation examines whether these predictions exhibit biases across different demographic groups. Both are vital for model evaluation, serving distinct purposes. Interpretability aids in comprehending how the model functions internally, while fairness assessment ensures equitable outcomes for all demographic groups. Thus, integrating both modules into your evaluation process offers a holistic view of your model’s performance and its impact on diverse populations.
Privacy and security
Ensure that your model adheres to privacy and security guidelines, particularly when handling sensitive data. Implement appropriate measures to protect data confidentiality and integrity.
Incorporating custom code components in your training pipeline allows you to extend the functionality of Azure Machine Learning Designer with specialized processing tasks.
Evaluating your model with a focus on performance metrics and Responsible AI principles ensures that your model is not only accurate but also fair, transparent, and secure. Figure 2-7 illustrates the process of making decisions on model fairness.
FIGURE 2.7 Ensuring model fairness in AI training