Azure Machine Learning is a cloud-based machine learning service provided by Microsoft that enables users to build, deploy, and manage machine learning models at scale. It provides a range of tools and frameworks that make it easier to create, use and manage machine learning models.
This tutorial will provide an introduction to Azure Machine Learning and walk you through the steps required to create, train and deploy a simple machine learning model using the Azure Machine Learning service.
Prerequisites
Before getting started with this tutorial, you will need to have the following:
- An active Azure account
- Basic knowledge of machine learning
- A basic understanding of Python
Step 1: Create an Azure Machine Learning workspace
The first step in using Azure Machine Learning is to create a workspace. This is where all the data, models, and experiments will be stored.
To create a workspace, follow the steps below:
- Log in to your Azure account.
- From the Azure portal dashboard, click on the “Create a resource” button on the top left corner.
- Search for “Azure Machine Learning” and select it from the list of available services.
- Click on the “Create” button to start the process of creating an Azure Machine Learning workspace.
- Fill in the details for the workspace such as the name, subscription, resource group, and location.
- Once the details are filled in, click on the “Review + Create” button.
- Review the details and then click on the “Create” button.
Once the workspace is created, you will see it listed in the resources section of your Azure portal dashboard. Click on the workspace to open it and access the tools and services available.
Step 2: Create a Machine Learning experiment in Azure
In Azure Machine Learning, an experiment is a collection of code, data, and configuration files that are used to create and train a machine learning model.
To create an experiment, follow the steps below:
- In the Azure Machine Learning workspace, click on the “Experiments” tab on the left-hand side.
- Click on the “New Experiment” button.
- Give the experiment a name and a description.
- Choose the type of experiment – Blank experiment, from sample code, from summited code run or from Azure noteboooks.
- Select the appropriate environment or kernel for the code execution.
- Click on the “Create” button.
Once the experiment is created, you will be taken to the experiment page where you can add code, data, and configuration files.
Step 3: Create a Machine Learning model in Python
Now that the experiment has been created, we can start working on building and training our machine learning model.
In this tutorial, we will be creating a simple machine learning model using Python. We will be using a dataset of student scores to predict future scores based on their study hours.
To create the machine learning model, follow the steps below:
- Open the experiment in the Azure Machine Learning workspace.
- Create a new Python file by clicking on the “New File” button in the top-left corner.
- Name the file, e.g.
train.py
. - Paste the following code into the file:
# Importing the required libraries
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn import metrics
# Reading the data
data = pd.read_csv('data.csv')
# Splitting the data into training and testing sets
X = data['StudyHours'].values.reshape(-1,1)
y = data['Scores'].values.reshape(-1,1)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
# Creating and training the model
model = LinearRegression()
model.fit(X_train, y_train)
# Making predictions on the test set
y_pred = model.predict(X_test)
# Evaluating the model performance
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
This code reads the data from a CSV file called data.csv
, splits the data into training and testing sets, creates a linear regression model, trains the model, and then evaluates its performance by printing out the mean absolute error, mean squared error and root mean squared error.
- Save the file.
Step 4: Upload the data to Azure
In Azure Machine Learning, data can be uploaded to the workspace for use in experiments and models.
To upload the data, follow the steps below:
- In the Azure Machine Learning workspace, click on the “Datasets” tab on the left-hand side.
- Click on the “New Dataset” button.
- Select the type of dataset – create manually, from local file or from web files.
- Upload the
data.csv
file. - Fill in the details such as the name, file type and description.
- Click on the “Create” button.
Once the dataset is created, you will see it listed in the datasets section of your Azure Machine Learning workspace.
Step 5: Run the experiment
Now that the data and model code are uploaded to Azure Machine Learning, we can run the experiment and train our machine learning model.
To run the experiment, follow the steps below:
- Open the experiment in the Azure Machine Learning workspace.
- Click on the “Run” button on the top to run the experiment.
- Choose the source directory and the file
train.py
. - Choose or create a compute target.
- Choose any diagnostics logs or metrics that need to be logged.
- Click on the “Submit” button to start running the experiment.
Once the experiment is running, you can monitor its progress in real-time from the “Run details” page.
Step 6: Deploy the Machine Learning model
The final step in using Azure Machine Learning is to deploy the machine learning model.
To deploy the model, follow the steps below:
- Click on the “Deployments” tab on the left-hand side menu of the Azure Machine Learning workspace.
- Click on the “New Deployment” button.
- Choose the deployment target, such as Azure Container Instance or Azure Kubernetes Service.
- Choose the model and the associated assets needed to run the deployed model.
- Fill in the deployment details such as the name, description, and resource group.
- Click on the “Create” button.
Once the model is deployed, you can access it from the “Endpoints” tab in the Azure Machine Learning workspace.
Conclusion
In this tutorial, we walked through the basics of Azure Machine Learning and created a simple machine learning model using Python. We created an experiment in Azure Machine Learning, uploaded data to the workspace, ran the experiment, and finally deployed the model.
Azure Machine Learning is a powerful tool that can help you create, deploy, and manage machine learning models at scale. It provides an easy-to-use platform for building and training machine learning models, and its integration with other Azure services makes it an excellent choice for any organization looking to implement machine learning solutions.