Differences between AWS Sagemaker and Azure ML Studio
Dhiraj Patra
Cloud-Native Architect | AI, ML, GenAI Innovator & Mentor | Quantitative Financial Analyst
Here are some of the key differences between AWS SageMaker and Azure Machine Learning Studio:
AWS SageMaker
SageMaker pricing is based on the number of compute hours used, the amount of data stored, and the number of requests made.
SageMaker is a fully managed service, which means that Amazon takes care of all the underlying infrastructure. This makes it easy to get started with machine learning, but it also limits your flexibility.
SageMaker offers a wide range of features, including:
Here is an example of how to use AWS SageMaker to train a machine learning model:
import sagemake
# Create a SageMaker session.
session = sagemaker.Session()
# Create a bucket to store your data.
bucket = session.default_bucket()
# Upload your data to the bucket.
session.upload_data(path="data/train.csv", bucket=bucket, key="train.csv")
# Create a SageMaker training job.
job = sagemaker.create_training_job(
? ? name="my-training-job",
? ? image="sagemaker-scikit-learn:0.23-1",
? ? hyperparameters={"max_iter": 100},
? ? inputs={"train": {"s3_uri": f"s3://{bucket}/train.csv"}},
? ? output_path=f"s3://{bucket}/output",
)
# Wait for the training job to complete.
job.wait_until_complete()
# Get the trained model.
model = job.outputs["model"]
# Deploy the model.
predictor = model.deploy(
? ? endpoint_name="my-endpoint",
? ? instance_type="ml.m4.xlarge",
? ? worker_count=1,
)
# Make a prediction.
prediction = predictor.predict(
? ? data={"features": {"x": 1, "y": 2}}
)
# Print the prediction.
print(prediction)
Now, Azure Machine Learning Studio
Azure Machine Learning Studio pricing is based on the number of compute hours used, the amount of data stored, and the number of users.
Azure Machine Learning Studio is a managed service, but it also gives you more flexibility to choose your own infrastructure. This can be more complex, but it also gives you more control.
Here is an example of how to use Azure Machine Learning Studio to train a machine learning model:
import sagemake
# Create a SageMaker session.
session = sagemaker.Session()
# Create a bucket to store your data.
bucket = session.default_bucket()
# Upload your data to the bucket.
session.upload_data(path="data/train.csv", bucket=bucket, key="train.csv")
# Create a SageMaker training job.
job = sagemaker.create_training_job(
? ? name="my-training-job",
? ? image="sagemaker-scikit-learn:0.23-1",
? ? hyperparameters={"max_iter": 100},
? ? inputs={"train": {"s3_uri": f"s3://{bucket}/train.csv"}},
? ? output_path=f"s3://{bucket}/output",
)
# Wait for the training job to complete.
job.wait_until_complete()
# Get the trained model.
model = job.outputs["model"]
# Deploy the model.
predictor = model.deploy(
? ? endpoint_name="my-endpoint",
? ? instance_type="ml.m4.xlarge",
? ? worker_count=1,
)
# Make a prediction.
prediction = predictor.predict(
? ? data={"features": {"x": 1, "y": 2}}
)
# Print the prediction.
print(prediction)
Another way I am explaing below.
AWS SageMaker and Azure Machine Learning Studio are both cloud-based platforms that provide tools and services for building, training, and deploying machine learning models. While they have similar goals, there are some differences in their approach and feature set. Let's explore these differences along with a code example for each platform.
领英推荐
import sagemake
from sagemaker import get_execution_role
from sagemaker.amazon.amazon_estimator import get_image_uri
# Set up SageMaker session and role
session = sagemaker.Session()
role = get_execution_role()
# Get the container image for Linear Regression
container = get_image_uri(session.boto_region_name, 'linear-learner')
# Create an estimator for training
estimator = sagemaker.estimator.Estimator(container,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? role,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? train_instance_count=1,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? train_instance_type='ml.m4.xlarge',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? output_path='s3://<bucket_name>/output')
# Set hyperparameters and data inputs
estimator.set_hyperparameters(feature_dim=10, predictor_type='regressor')
estimator.fit({'train': 's3://<bucket_name>/train_data.csv'})
Azure Machine Learning Studio:
Overall, while both AWS SageMaker and Azure Machine Learning Studio offer similar capabilities, SageMaker provides a more extensive set of features and allows for more programmatic control, while Azure Machine Learning Studio focuses on a visual drag-and-drop approach, suitable for users who prefer a code-free experience.
Here's a code example using Python and the Azure Machine Learning Python SDK for training a classification model using Azure Machine Learning:
from azureml.core import Workspace, Experimen
from azureml.train import automl
# Connect to Azure Machine Learning workspace
ws = Workspace.from_config()
# Create an experiment
experiment = Experiment(workspace=ws, name='automl-example')
# Define training data and target column
training_data = 'https://<your-training-data-url>'
target_column = 'target'
# Configure AutoML settings
automl_settings = {
? ? "iteration_timeout_minutes": 10,
? ? "iterations": 5,
? ? "primary_metric": 'AUC_weighted',
? ? "preprocess": True,
? ? "verbosity": logging.INFO,
? ? "n_cross_validations": 3
}
# Define AutoML configuration
automl_config = automl.AutoMLConfig(
? ? task='classification',
? ? debug_log='automl_errors.log',
? ? training_data=training_data,
? ? label_column_name=target_column,
? ? **automl_settings
)
# Submit the experiment for model training
run = experiment.submit(automl_config, show_output=True)
# Get the best model
best_model, fitted_model = run.get_output()
# Save the model
model_name = 'automl-classification-model'
model_path = './outputs/' + model_name
fitted_model.save(model_path)
# Register the model in Azure Machine Learning workspace
model = run.register_model(model_name=model_name, model_path=model_path)
# Deploy the model as a web service
from azureml.core.model import InferenceConfig, Model
from azureml.core.webservice import AciWebservice
from azureml.core.environment import Environment
# Define inference configuration
inference_config = InferenceConfig(entry_script='score.py', environment=env)
# Define deployment configuration
deployment_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1)
# Deploy the model as a web service
service_name = 'automl-classification-service'
service = Model.deploy(workspace=ws,
? ? ? ? ? ? ? ? ? ? ? ?name=service_name,
? ? ? ? ? ? ? ? ? ? ? ?models=[model],
? ? ? ? ? ? ? ? ? ? ? ?inference_config=inference_config,
? ? ? ? ? ? ? ? ? ? ? ?deployment_config=deployment_config,
? ? ? ? ? ? ? ? ? ? ? ?overwrite=True)
# Wait for the deployment to complete
service.wait_for_deployment(show_output=True)
# Test the web service endpoint with sample data
input_data = {
? ? 'data': [
? ? ? ? [1.0, 2.0, 3.0, 4.0],
? ? ? ? [4.0, 3.0, 2.0, 1.0]
? ? ]
}
result = service.run(input_data)
print(result)
Please note that you would need to install the azureml-sdk Python package and have an existing Azure Machine Learning workspace configured with appropriate credentials for this code to work.
Thank you.
Hi Dhiraj, Nice article. Please be aware that it seems you have posted the wrong image for the example of how to use Azure Machine Learning Studio. (2nd images in your post) Currently it is the same image as the AWS Sagemaker above it.