Skip to content

Commit d4ba7f4

Browse files
authored
add in progress
1 parent 960ca29 commit d4ba7f4

File tree

1 file changed

+79
-12
lines changed

1 file changed

+79
-12
lines changed

azML-modelcreation/README.md

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,26 @@ Last updated: 2025-04-29
1313
<details>
1414
<summary><b>List of References </b> (Click to expand)</summary>
1515

16+
- [AutoML Regression](https://learn.microsoft.com/en-us/azure/machine-learning/component-reference-v2/regression?view=azureml-api-2)
17+
- [Evaluate automated machine learning experiment results](https://learn.microsoft.com/en-us/azure/machine-learning/how-to-understand-automated-ml?view=azureml-api-2)
18+
- [Evaluate Model component](https://learn.microsoft.com/en-us/azure/machine-learning/component-reference/evaluate-model?view=azureml-api-2)
19+
1620
</details>
1721

1822
<details>
1923
<summary><b>Table of Content </b> (Click to expand)</summary>
2024

25+
- [Step 1: Set Up Your Azure ML Workspace](#step-1-set-up-your-azure-ml-workspace)
26+
- [Step 2: Create a Compute Instance](#step-2-create-a-compute-instance)
27+
- [Step 3: Prepare Your Data](#step-3-prepare-your-data)
28+
- [Step 4: Create a New Notebook or Script](#step-4-create-a-new-notebook-or-script)
29+
- [Step 5: Load and Explore the Data](#step-5-load-and-explore-the-data)
30+
- [Step 6: Train Your Model](#step-6-train-your-model)
31+
- [Step 7: Evaluate the Model](#step-7-evaluate-the-model)
32+
- [Step 8: Register the Model](#step-8-register-the-model)
33+
- [Step 9: Deploy the Model](#step-9-deploy-the-model)
34+
- [Step 10: Test the Endpoint](#step-10-test-the-endpoint)
35+
2136
</details>
2237

2338
## Step 1: Set Up Your Azure ML Workspace
@@ -227,29 +242,81 @@ https://github.com/user-attachments/assets/a82ff03e-437c-41bc-85fa-8b9903384a5b
227242
228243
## Step 9: Deploy the Model
229244

245+
> Create the Scoring Script:
246+
247+
```python
248+
import joblib
249+
import numpy as np
250+
from azureml.core.model import Model
251+
252+
def init():
253+
global model
254+
model_path = Model.get_model_path("my_model_RegressionModel")
255+
model = joblib.load(model_path)
256+
257+
def run(data):
258+
try:
259+
input_data = np.array(data["data"])
260+
result = model.predict(input_data)
261+
return result.tolist()
262+
except Exception as e:
263+
return str(e)
264+
```
265+
266+
https://github.com/user-attachments/assets/cdc64857-3bde-4ec9-957d-5399d9447813
267+
268+
> Create the Environment File (env.yml):
269+
270+
https://github.com/user-attachments/assets/8e7c37a2-e32b-4630-8516-f95926c374c0
271+
272+
> Create a new notebook:
273+
274+
https://github.com/user-attachments/assets/1b3e5602-dc64-4c39-be72-ed1cbd74361e
275+
230276
> Create an **inference configuration** and deploy to a web service:
231277
232278
```python
279+
from azureml.core import Workspace
233280
from azureml.core.environment import Environment
234-
from azureml.core.model import InferenceConfig
281+
from azureml.core.model import InferenceConfig, Model
235282
from azureml.core.webservice import AciWebservice
236-
237-
env = Environment.from_conda_specification(name="myenv", file_path="env.yml")
283+
284+
# Load the workspace
285+
ws = Workspace.from_config()
286+
287+
# Get the registered model
288+
registered_model = Model(ws, name="my_model_RegressionModel")
289+
290+
# Create environment from requirements.txt (no conda)
291+
env = Environment.from_pip_requirements(
292+
name="regression-env",
293+
file_path="requirements.txt" # Make sure this file exists in your working directory
294+
)
295+
296+
# Define inference configuration
238297
inference_config = InferenceConfig(entry_script="score.py", environment=env)
239-
298+
299+
# Define deployment configuration
240300
deployment_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1)
241-
service = Model.deploy(workspace=ws,
242-
name="my-service",
243-
models=[model],
244-
inference_config=inference_config,
245-
deployment_config=deployment_config)
301+
302+
# Deploy the model
303+
service = Model.deploy(
304+
workspace=ws,
305+
name="regression-model-service",
306+
models=[registered_model],
307+
inference_config=inference_config,
308+
deployment_config=deployment_config
309+
)
310+
246311
service.wait_for_deployment(show_output=True)
312+
print(f"Scoring URI: {service.scoring_uri}")
247313
```
248314

249-
---
250315

251-
### **10. Test the Endpoint**
252-
- Once deployed, you can send HTTP requests to the endpoint to get predictions.
316+
317+
## Step 10: Test the Endpoint
318+
319+
> Once deployed, you can send HTTP requests to the endpoint to get predictions.
253320
254321

255322

0 commit comments

Comments
 (0)