Skip to content

Commit 6a07ef6

Browse files
authored
Merge pull request #6 from MicrosoftCloudEssentials-LearningHub/azml-model
how to create an azure machine learning model
2 parents cf51617 + f9e837a commit 6a07ef6

File tree

4 files changed

+50185
-12
lines changed

4 files changed

+50185
-12
lines changed

README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Last updated: 2025-04-29
1515
- Terraform [Demonstration: Deploying Azure Resources for a Data Platform (Microsoft Fabric)](./infrastructure/msFabric/)
1616
- Terraform [Demonstration: Deploying Azure Resources for an ML Platform](./infrastructure/azMachineLearning/)
1717
- [Demostration: How to integrate AI in Microsoft Fabric](./msFabric-AI_integration/)
18+
- [Demostration: Creating a Machine Learning Model](./azML-modelcreation/)
1819

1920
> Azure Machine Learning (PaaS) is a cloud-based platform from Microsoft designed to help `data scientists and machine learning engineers build, train, deploy, and manage machine learning models at scale`. It supports the `entire machine learning lifecycle, from data preparation and experimentation to deployment and monitoring.` It provides powerful tools for `both code-first and low-code users`, including Jupyter notebooks, drag-and-drop interfaces, and automated machine learning (AutoML). `Azure ML integrates seamlessly with other Azure services and supports popular frameworks like TensorFlow, PyTorch, and Scikit-learn.`
2021
@@ -228,18 +229,6 @@ Read more about [Endpoints for inference in production](https://learn.microsoft.
228229
| **Attached Compute** | External compute resources manually connected to Azure ML. | Leverage existing infrastructure. | Using Azure VMs, Databricks, or on-prem compute. | Flexibility, hybrid cloud support, reuse of existing resources. |
229230
| **Serverless Instances** | Lightweight, on-demand compute (e.g., Azure Container Instances). | Quick testing and low-scale inference. | Temporary model deployment, dev/test environments. | No infrastructure management, fast startup, cost-effective. |
230231

231-
> How to create a Compute Instance:
232-
233-
1. **Go to Azure Machine Learning Studio**: Navigate to [ml.azure.com](https://ml.azure.com/) and select your workspace.
234-
2. **Select `Compute` from the left menu** Choose the **`Compute instances`** tab.
235-
3. **Click `New`**
236-
- Enter a name for your compute instance.
237-
- Choose a virtual machine size (e.g., `Standard_DS3_v2`).
238-
- Optionally, enable SSH access or assign a user.
239-
4. **Click `Create`**: Azure will provision the compute instance, which may take a few minutes.
240-
241-
https://github.com/user-attachments/assets/bd5f3ce6-7082-4741-8827-8b344cd249a4
242-
243232
</details>
244233

245234
<details>

azML-modelcreation/README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Demostration: Creating a Machine Learning Model
2+
3+
Costa Rica
4+
5+
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
6+
[brown9804](https://github.com/brown9804)
7+
8+
Last updated: 2025-04-29
9+
10+
------------------------------------------
11+
12+
13+
<details>
14+
<summary><b>List of References </b> (Click to expand)</summary>
15+
16+
</details>
17+
18+
<details>
19+
<summary><b>Table of Content </b> (Click to expand)</summary>
20+
21+
</details>
22+
23+
## Step 1: Set Up Your Azure ML Workspace
24+
25+
> You can use the azure portal approach:
26+
27+
- Go to the [Azure Portal](https://portal.azure.com/)
28+
- Create a **Machine Learning workspace**:
29+
- Resource group
30+
- Workspace name
31+
- Region
32+
- Once created, launch **Azure Machine Learning Studio**.
33+
34+
https://github.com/user-attachments/assets/c199156f-96cf-4ed0-a8b5-c88db3e7a552
35+
36+
> Or using terraform configurations for setting up an Azure Machine Learning workspace along with compute clusters and supportive resources to form the core of an ML platform, click here to see [Demonstration: Deploying Azure Resources for an ML Platform](./infrastructure/azMachineLearning/README.md)
37+
38+
## Step 2: Create a Compute Instance
39+
40+
1. **Go to [Azure Machine Learning Studio](https://ml.azure.com/)** and select your workspace.
41+
2. **Select `Compute` from the left menu** Choose the **`Compute instances`** tab.
42+
3. **Click `New`**
43+
- Enter a name for your compute instance.
44+
- Choose a virtual machine size (e.g., `Standard_DS3_v2`).
45+
- Optionally, enable SSH access or assign a user.
46+
4. **Click `Create`**: Azure will provision the compute instance, which may take a few minutes.
47+
48+
https://github.com/user-attachments/assets/bd5f3ce6-7082-4741-8827-8b344cd249a4
49+
50+
## Step 3: Prepare Your Data
51+
52+
- Upload your dataset to **Azure ML datastore** or connect to exrnal sources (e.g., Azure Blob Storage, SQL, etc.).
53+
- Use **Data > Datasets** to register and version your dataset.
54+
55+
> For example: Upload the CSV to Azure ML
56+
57+
1. Under to **Data > + Create > From local files**.
58+
2. Choose:
59+
- **Name**: `employee_data`
60+
- **Type**: Tabular
61+
- **Browse** and upload the [sample_data.csv](./azML-modelcreation/data/sample_data.csv) file.
62+
3. Click **Next**, then **Review + Create**.
63+
64+
> Register the Dataset:
65+
66+
1. After upload, Azure will preview the data.
67+
2. Confirm the schema (column names and types).
68+
3. Click **Create** to register the dataset.
69+
70+
https://github.com/user-attachments/assets/f8cbd32c-94fc-43d3-a7a8-00f63cdc543d
71+
72+
73+
### **4. Create a New Notebook or Script**
74+
- Use the compute instance to open a **Jupyter notebook** or create a Python script.
75+
- Import necessary libraries:
76+
```python
77+
import pandas as pd
78+
from sklearn.model_selection import train_test_split
79+
from sklearn.ensemble import RandomForestClassifier
80+
from sklearn.metrics import accuracy_score
81+
```
82+
83+
---
84+
85+
### **5. Load and Explore the Data**
86+
- Load the dataset and perform basic EDA (exploratory data analysis):
87+
```python
88+
data = pd.read_csv('your_dataset.csv')
89+
print(data.head())
90+
```
91+
92+
---
93+
94+
### **6. Train Your Model**
95+
- Split the data and train a model:
96+
```python
97+
X = data.drop('target', axis=1)
98+
y = data['target']
99+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
100+
101+
model = RandomForestClassifier()
102+
model.fit(X_train, y_train)
103+
```
104+
105+
---
106+
107+
### **7. Evaluate the Model**
108+
- Check performance:
109+
```python
110+
predictions = model.predict(X_test)
111+
print("Accuracy:", accuracy_score(y_test, predictions))
112+
```
113+
114+
---
115+
116+
### **8. Register the Model**
117+
- Save and register the model in Azure ML:
118+
```python
119+
import joblib
120+
joblib.dump(model, 'model.pkl')
121+
122+
from azureml.core import Workspace, Model
123+
ws = Workspace.from_config()
124+
Model.register(workspace=ws, model_path="model.pkl", model_name="my_model")
125+
```
126+
127+
---
128+
129+
### **9. Deploy the Model**
130+
- Create an **inference configuration** and deploy to a web service:
131+
```python
132+
from azureml.core.environment import Environment
133+
from azureml.core.model import InferenceConfig
134+
from azureml.core.webservice import AciWebservice
135+
136+
env = Environment.from_conda_specification(name="myenv", file_path="env.yml")
137+
inference_config = InferenceConfig(entry_script="score.py", environment=env)
138+
139+
deployment_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1)
140+
service = Model.deploy(workspace=ws,
141+
name="my-service",
142+
models=[model],
143+
inference_config=inference_config,
144+
deployment_config=deployment_config)
145+
service.wait_for_deployment(show_output=True)
146+
```
147+
148+
---
149+
150+
### **10. Test the Endpoint**
151+
- Once deployed, you can send HTTP requests to the endpoint to get predictions.
152+
153+
154+
155+
<div align="center">
156+
<h3 style="color: #4CAF50;">Total Visitors</h3>
157+
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
158+
</div>

azML-modelcreation/data/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Sample Data
2+
3+
Costa Rica
4+
5+
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
6+
[brown9804](https://github.com/brown9804)
7+
8+
Last updated: 2025-04-29
9+
10+
------------------------------------------
11+
12+
> This dataset is a synthetic sample of employee records created for demonstration and training purposes in a machine learning workflow. This sample data is designed to simulate a
13+
> realistic HR dataset and will be used to build and evaluate a machine learning model for tasks such as salary prediction, employee segmentation, or attrition analysis.
14+
> It contains > 50,000 rows with the following attributes:
15+
16+
- **Name**: A randomly selected first name.
17+
- **Age**: An integer representing the employee's age (22–65).
18+
- **Department**: The department where the employee works (e.g., HR, Engineering, Sales).
19+
- **Salary**: The employee's annual salary in USD, ranging from \$40,000 to \$120,000.
20+
21+
22+
<div align="center">
23+
<h3 style="color: #4CAF50;">Total Visitors</h3>
24+
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
25+
</div>

0 commit comments

Comments
 (0)