Steps for Azure Machine Learning Model Deployment

 Deploying a Machine Learning model on Azure can be done through multiple ways depending on the service you choose (Azure ML Service, Azure App Service, Azure Container Instance, Azure Kubernetes Service). Since you are starting, I will guide you step-by-step for a simple and professional way using Azure Machine Learning Service (Azure ML Studio).


High-Level Steps for Azure ML Model Deployment


Step 1: Register on Azure ML Studio

  • Go to https://ml.azure.com

  • Create an Azure Machine Learning Workspace if you don't have one

  • Create or attach a Compute Instance for development (Jupyter Notebook support)


Step 2: Upload / Train / Register your Model

  1. Open the Notebook in Azure ML Studio

  2. Train your model or upload your already trained model (e.g., model.pkl)

  3. Save the model in a directory:

    python
    import joblib joblib.dump(model, 'model.pkl')
  4. Register the model:

    python
    from azureml.core import Workspace, Model ws = Workspace.from_config() model = Model.register(workspace=ws, model_path="model.pkl", model_name="my_model") print("Model Registered: ", model.name, model.version)

Step 3: Create Inference Script

Create a file called score.py to load the model and define the prediction logic:

python
import json import joblib import numpy as np import pandas as pd from azureml.core.model import Model def init(): global model model_path = Model.get_model_path('my_model') model = joblib.load(model_path) def run(raw_data): data = json.loads(raw_data) df = pd.DataFrame(data) result = model.predict(df) return json.dumps(result.tolist())

Step 4: Create Environment YAML

Create environment.yml

yaml
name: myenv dependencies: - python=3.8 - pandas - scikit-learn - joblib

Step 5: Create Inference Configuration

python
from azureml.core.environment import Environment from azureml.core.model import InferenceConfig env = Environment.from_conda_specification(name="myenv", file_path="environment.yml") inference_config = InferenceConfig(entry_script="score.py", environment=env)

Step 6: Deploy as Web Service

python
from azureml.core.webservice import AciWebservice deployment_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1) service = Model.deploy(workspace=ws, name="my-model-service", models=[model], inference_config=inference_config, deployment_config=deployment_config) service.wait_for_deployment(True) print(service.scoring_uri)

Step 7: Test the Deployment

python
import requests import json scoring_uri = service.scoring_uri data = json.dumps([{"feature1": value1, "feature2": value2, ... }]) headers = {"Content-Type": "application/json"} response = requests.post(scoring_uri, data=data, headers=headers) print(response.text)

✅ Notes:

  • If you want to expose it publicly or integrate with your app, you can use the scoring_uri

  • You can also deploy the model to Azure Kubernetes Service for production scale

  • Azure ML also supports Managed Online Endpoints if you prefer drag and drop

No comments

Theme images by tjasam. Powered by Blogger.