Showing posts with label sagemaker. Show all posts
Showing posts with label sagemaker. Show all posts

Friday

Differences between AWS Sagemaker and Azure ML Studio

 

unplash

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:

  • Data preparation and preprocessing
  • Model training and tuning
  • Model deployment and monitoring | Azure Machine Learning Studio offers a similar range of features, but it also includes:
  • A drag-and-drop interface for creating machine learning models
  • A visual workspace for managing your machine learning projects
  • Integration with other Azure services

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.

  1. AWS SageMaker:
  • SageMaker provides a fully managed platform with a wide range of machine learning capabilities, including data preprocessing, model training, hyperparameter tuning, and model deployment.
  • It offers a variety of built-in algorithms and frameworks, such as TensorFlow, PyTorch, XGBoost, etc., allowing users to choose the one that suits their needs.
  • SageMaker supports Jupyter notebooks for interactive development and provides a Python SDK for programmatic access to its features.
  1. Code Example — Training a Linear Regression Model using SageMaker:
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:

  • Azure Machine Learning Studio is a drag-and-drop interface that allows users to build machine learning models using a visual interface without writing code.
  • It provides a wide range of pre-built modules for various tasks, such as data preprocessing, feature engineering, model training, and evaluation.
  • Azure Machine Learning Studio supports various programming languages, including Python, R, and SQL, for advanced scripting and customization.
  1. Code Example — Training a Logistic Regression Model using Azure Machine Learning Studio (visual interface):
  2. Select the “Data” tab and import your training dataset.
  3. Select the “Machine Learning” tab and drag the “Train Model” module to the canvas.
  4. Connect the dataset to the “Train Model” module.
  5. Configure the “Train Model” module to use the Logistic Regression algorithm and set the desired parameters.
  6. Select the “Run” button to start the training process.
  7. Note: In Azure Machine Learning Studio, the process is performed visually without writing code. However, you have the option to incorporate scripting using Python or R within the modules if needed.

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.