Certification target: AI-900 — 2nd course in the AI Fundamentals series Exam module: 15-20% of the exam Level: Beginner
Table of Contents
- Introduction to Machine Learning
- Types of Machine Learning
- Data Preparation
- Algorithms and Microsoft Cheat Sheet
- Azure Automated Machine Learning (AutoML)
- Azure Machine Learning Designer
- Evaluating Regression Models
- Classification Models and Confusion Matrix
- Clustering – Unsupervised Grouping
- Deep Learning
- Inference Pipelines and Deployment
- Practical Implementation with Python and SDK
- Exam Tips and Common Pitfalls
- Summary and Key Points
- Glossary
1. Introduction to Machine Learning
1.1 What is Machine Learning?
Machine Learning (ML) is a technique that uses mathematics and statistics to create a model capable of predicting unknown values.
Good news: You don’t need to know the mathematical formulas for the AI-900 exam or to use Azure ML!
Simple analogy: You work at a car dealership. You want to estimate the price of a vehicle based on its engine, fuel consumption, and mileage. You have historical sales data. You train a model on that data → the model learns the patterns → it can predict the price of an unknown car.
flowchart LR
HIST["📊 Historical Data\n(Dataset)\n\nEx: 500 cars\nwith specs + prices"]
TRAIN["🔧 Training\n\nAlgorithm learns\nthe patterns"]
MODEL["🧠 Trained Model\n\n.pkl/.joblib file\nContains learned patterns"]
PREDICT["🔮 Predictions\n\nNew car\n→ Estimated price: $25,000"]
HIST --> TRAIN --> MODEL --> PREDICT
1.2 Essential Terminology for the Exam
| Term | Definition | Example |
|---|---|---|
| Dataset | Collection of data (table, CSV) | 500 cars with specs and prices |
| Feature (Variable) | Model input column | Engine size, fuel consumption |
| Label | Value to predict | Car price |
| Training | Model learning process | Running the algorithm on data |
| Model | File resulting from training | The “brain” that makes predictions |
| Inference (Scoring) | Using the model to predict | Send a new car → get the price |
| Algorithm | Mathematical learning method | Linear Regression, Random Forest |
2. Types of Machine Learning
2.1 Overview
flowchart TD
ML["Machine Learning"] --> SUPERVISED["Supervised\n(with labels)"]
ML --> UNSUPERVISED["Unsupervised\n(without labels)"]
ML --> DL["Deep Learning\n(subset of ML)"]
SUPERVISED --> REG["Regression\n(Predict a number)"]
SUPERVISED --> CLASS["Classification\n(Predict a category)"]
UNSUPERVISED --> CLUST["Clustering\n(Group elements)"]
CLASS --> BINARY["Binary\n(2 classes: Yes/No)"]
CLASS --> MULTI["Multi-class\n(3+ classes)"]
DL --> NN["Neural Networks\n(Images, text, audio)"]
2.2 Regression
Regression = Predict a continuous numeric value.
flowchart LR
FEATURES["Features\n• Engine size: 1500cc\n• Fuel consumption: 8L/100km\n• Mileage: 45000km\n• Year: 2018"] --> MODEL["🧠 Regression Model"]
MODEL --> LABEL["Predicted Label\n💰 Price: $18,500"]
Business examples:
| Domain | Features | Predicted Label |
|---|---|---|
| Real Estate | Area, location, bedrooms | Selling price |
| Finance | Income, debts, tenure | Approved loan amount |
| Weather | Temperature, humidity, pressure | Tomorrow’s temperature |
| Energy | Time, weather, day of week | Power consumption |
| Retail | Sales history, seasonality | Future sales |
Exam keywords: “predict an amount”, “estimate a value”, “forecast”
2.3 Classification
Classification = Predict which category an element belongs to.
Type 1 – Binary (2 classes):
Input: Customer data (income, debts, credit score, history)
Output: APPROVED (1) or DENIED (0)
Type 2 – Multi-class (3+ classes):
Input: Photo of an animal
Output: DOG (30%) | CAT (65%) | RABBIT (5%)
→ Predicted class: CAT
Business examples:
| Domain | Classes | Type |
|---|---|---|
| Banking | Fraud/Legitimate | Binary |
| Spam/Ham | Binary | |
| Diabetes | Diabetic/Non-diabetic | Binary |
| Sentiment | Positive/Neutral/Negative | Multi-class |
| Income | ≤50K/>50K | Binary |
2.4 Clustering
Clustering = Group similar elements without predefined labels.
Fundamental difference: Regression and Classification are supervised (the answer is known in training data). Clustering is unsupervised (we don’t know in advance how many groups exist).
flowchart LR
DATA["📊 Data\n(Penguins)\n\n• Bill length\n• Bill depth\n• Flipper length\n• Body mass"] --> KMEANS["K-Means Clustering\n(Algorithm)"]
KMEANS --> G1["🐧 Group 1\n(Adelie Penguin)"]
KMEANS --> G2["🐧 Group 2\n(Gentoo Penguin)"]
KMEANS --> G3["🐧 Group 3\n(Chinstrap Penguin)"]
Examples:
- Customer segmentation: group customers by purchasing behavior
- Anomaly detection: isolated points are suspicious
- Data exploration: discover hidden patterns
K-Means is the clustering algorithm available in Azure ML Designer. The K parameter defines the desired number of clusters.
2.5 Deep Learning
Deep Learning = A subset of ML using multi-layer artificial neural networks to find patterns in complex, unstructured data.
flowchart LR
subgraph "Neural Network"
INPUT["Input Layer\n(Image pixels)"] --> H1["Hidden Layer 1\n(Edges, textures)"]
H1 --> H2["Hidden Layer 2\n(Shapes, patterns)"]
H2 --> H3["Hidden Layer 3\n(Objects, faces)"]
H3 --> OUTPUT["Output Layer\n('It's a dog')"]
end
Deep Learning use cases:
- Images: Classification, object detection
- Text: Translation, sentiment, generation
- Audio: Speech-to-text, music recognition
- Video: Motion detection
When to use Deep Learning vs. classical ML:
| Classical ML | Deep Learning | |
|---|---|---|
| Data | Structured (tables) | Unstructured (images, text, audio) |
| Volume | Small to medium | Large (thousands of examples) |
| Compute | CPU sufficient | GPU recommended |
| Explainability | Good | Difficult (black box) |
| Azure examples | AutoML, Designer | Azure AI Vision, Language, Speech |
3. Data Preparation
3.1 Why Prepare Data?
“Garbage in, garbage out”: A model trained on bad data will give bad predictions, regardless of algorithm sophistication.
flowchart LR
RAW["📊 Raw Data\n(Potential issues)"] --> CLEAN["🧹 Cleaning"]
CLEAN --> NORM["📏 Normalization"]
NORM --> SPLIT["✂️ Split\n(Train/Test Split)"]
SPLIT --> READY["✅ Data ready\nfor training"]
3.2 Cleaning
Common problems and solutions:
| Problem | Solution | Example |
|---|---|---|
| Missing values (NaN) | Remove the row OR impute (mean, median) | normalized-losses: NaN → Remove row |
| Duplicates | Remove duplicated rows | Same sale twice |
| Outliers | Remove or replace if aberrant | Age = 500 years |
| Irrelevant columns | Remove (e.g., columns with too many NaN) | normalized-losses (60% NaN) |
| Inconsistencies | Standardize formats | ”France” / “france” / “FR” |
# Data cleaning with pandas
import pandas as pd
import numpy as np
df = pd.read_csv("automobile_price.csv")
print("=== Initial State ===")
print(f"Shape: {df.shape}")
print(f"Missing values:\n{df.isnull().sum()}")
# 1. Remove columns with > 50% NaN
nan_threshold = len(df) * 0.5
df = df.dropna(axis=1, thresh=nan_threshold)
print(f"\nAfter removing NaN columns: {df.shape}")
# 2. Remove rows with remaining NaN
df_clean = df.dropna()
print(f"After removing NaN rows: {df_clean.shape}")
print(f"Rows removed: {len(df) - len(df_clean)}")
# 3. Remove duplicates
df_clean = df_clean.drop_duplicates()
print(f"After removing duplicates: {df_clean.shape}")
# 4. Remove price outliers (example: remove price > 200,000)
q_low = df_clean["price"].quantile(0.01)
q_high = df_clean["price"].quantile(0.99)
df_clean = df_clean[df_clean["price"].between(q_low, q_high)]
print(f"After removing price outliers: {df_clean.shape}")
print("\n✅ Data cleaned!")
3.3 Normalization
Problem: If one feature has values from 0 to 2000 and another from 0 to 60, the first may dominate learning and bias the model.
Solution: Bring all features to the same scale (typically 0 to 1).
Before normalization:
Engine size: 1500 cc
Fuel consumption: 8 L/100km
→ The model "thinks" engine size is 187x more important!
After normalization (Min-Max Scaling):
Engine size: 0.75 (1500 on a scale of 0-2000)
Fuel consumption: 0.13 (8 on a scale of 0-60)
→ Same relative importance
# Normalization with scikit-learn
from sklearn.preprocessing import MinMaxScaler, StandardScaler
import pandas as pd
import numpy as np
# Sample data
X = pd.DataFrame({
"engine_size": [900, 1200, 1500, 2000],
"fuel_consumption": [6, 8, 12, 7],
"mileage": [10000, 45000, 80000, 25000]
})
print("Before normalization:")
print(X)
print(f"\nMeans: {X.mean().round(2).to_dict()}")
# Min-Max Scaling (0 to 1)
scaler_minmax = MinMaxScaler()
X_normalized = pd.DataFrame(
scaler_minmax.fit_transform(X),
columns=X.columns
)
print("\nAfter Min-Max Scaling (0 to 1):")
print(X_normalized.round(4))
# Standardization (mean=0, std=1)
scaler_std = StandardScaler()
X_standardized = pd.DataFrame(
scaler_std.fit_transform(X),
columns=X.columns
)
print("\nAfter Standardization (μ=0, σ=1):")
print(X_standardized.round(4))
# IMPORTANT: Save the scaler for inference!
import joblib
joblib.dump(scaler_minmax, "scaler.joblib")
print("\n✅ Scaler saved (needed for inference)")
Important for the exam: Normalization is not always necessary. If your data doesn’t have very different scales, you can skip it.
3.4 Train/Test Split
Why split? To evaluate the model on data it has never seen during training → otherwise you measure memorization, not generalization.
flowchart LR
DATASET["📊 Dataset\n(100% of data)"] --> SPLIT["✂️ Split"]
SPLIT --> TRAIN["🏋️ Training Set\n(70-80%)\n\n→ Train the model\n(learning)"]
SPLIT --> TEST["🧪 Test Set\n(20-30%)\n\n→ Evaluate the model\n(real performance)"]
TRAIN --> MODEL["🧠 Trained Model"]
MODEL --> EVAL["📊 Metrics\n(on test set)"]
TEST --> EVAL
Typical ratios:
- 70/30: Standard for most cases
- 80/20: When you have a lot of data
- 90/10: For very small datasets
from sklearn.model_selection import train_test_split
import pandas as pd
df = pd.read_csv("automobile_price.csv")
# Features and label
X = df.drop("price", axis=1)
y = df["price"]
# 80/20 split with stratification (for classification)
X_train, X_test, y_train, y_test = train_test_split(
X, y,
test_size=0.2, # 20% for testing
random_state=42, # For reproducibility
# stratify=y # For classification: preserve class proportions
)
print(f"Total: {len(df)} rows")
print(f"Train: {len(X_train)} rows ({len(X_train)/len(df):.0%})")
print(f"Test: {len(X_test)} rows ({len(X_test)/len(df):.0%})")
4. Algorithms and Microsoft Cheat Sheet
4.1 Microsoft Algorithm Selection Cheat Sheet
Microsoft provides a visual guide for choosing the algorithm based on:
- Problem type (classification, regression, clustering)
- Data size
- Objective (accuracy, speed, interpretability)
flowchart TD
Q1{"What problem?"}
Q1 -->|"Predict a number"| REG["Regression"]
Q1 -->|"Predict a category"| CLASS["Classification"]
Q1 -->|"Group elements"| CLUST["Clustering"]
REG --> R1["Linear Regression\n(Linear relationship)"]
REG --> R2["Boosted Decision Tree\nRegression (Complex)"]
REG --> R3["Neural Network\nRegression (Non-linear)"]
CLASS --> C1["Two-Class LR\n(Binary, interpretable)"]
CLASS --> C2["Two-Class Decision\nForest (Robust)"]
CLASS --> C3["Multi-Class LR\n(Multi-class)"]
CLUST --> K["K-Means Clustering\n(Only option\nin Designer)"]
4.2 Algorithms in Azure ML Designer
| Algorithm | Type | Use Case |
|---|---|---|
| Linear Regression | Regression | Simple linear relationships |
| Boosted Decision Tree Regression | Regression | Complex relationships, tabular data |
| Neural Network Regression | Regression | Highly non-linear patterns |
| Two-Class Logistic Regression | Binary Classification | Interpretable, linear data |
| Two-Class Boosted Decision Tree | Binary Classification | Powerful, complex data |
| Two-Class Decision Forest | Binary Classification | Robust, few parameters |
| Multiclass Decision Forest | Multi-class | Good general performance |
| K-Means Clustering | Clustering | Only clustering algorithm in Designer |
5. Azure Automated Machine Learning (AutoML)
5.1 What is AutoML?
AutoML = The “autopilot” version of Azure ML. You provide the data and problem type, Azure automatically tries dozens of algorithms and returns the best one.
flowchart LR
DATA["📊 Dataset"] --> AUTOML["⚙️ Azure AutoML\n\n1. Auto preprocessing\n2. Feature engineering\n3. Tries 20+ algorithms\n4. Hyperparameter tuning\n5. Model ensembling"]
AUTOML --> LEADERBOARD["🏆 Leaderboard\n\nAlgorithm 1: R²=0.94\nAlgorithm 2: R²=0.92\nAlgorithm 3: R²=0.89\n..."]
LEADERBOARD --> BEST["✅ Best model\nautomatically selected"]
5.2 Demo: Regression with AutoML (Bike Rentals)
Scenario: Predict the number of bike rentals based on weather, season, etc.
Workflow in Azure ML Studio:
1. Create a Dataset
→ Automated ML → Data → Create dataset
→ Choose: "Bike Rentals Dataset"
→ Preview and confirm
2. Configure the AutoML job
→ Automated ML → New Automated ML Job
→ Task type: Regression
→ Target column: rentals (number of rentals)
→ Training data: bike-rentals-dataset
3. Configuration
→ Primary metric: Normalized Root Mean Squared Error
→ Training time (hours): 0.5
→ Max concurrent trials: 4
4. Compute
→ Select existing cluster (e.g., Standard_DS11_v2)
5. Submit → Wait ~20-30 min
6. Analyze results
→ Jobs → Your job → Best model
→ View metrics: RMSE, R², MAE
→ Feature importance (which features matter most)
7. Deploy the best model
→ Deploy → Real-time endpoint
→ Test with new data
5.3 Using AutoML with SDK v2
# AutoML with Azure ML SDK v2
from azure.ai.ml import MLClient
from azure.ai.ml.automl import regression, RegressionPrimaryMetrics
from azure.ai.ml.entities import ResourceConfiguration
from azure.identity import DefaultAzureCredential
import os
ml_client = MLClient(
credential=DefaultAzureCredential(),
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"],
resource_group_name=os.environ["AZURE_RESOURCE_GROUP"],
workspace_name=os.environ["AZURE_ML_WORKSPACE"]
)
# AutoML regression job (bike rental prediction)
regression_job = regression(
training_data={
"data": {
"type": "mltable",
"path": "azureml:bike-rentals:1"
},
"target_column_name": "rentals"
},
primary_metric=RegressionPrimaryMetrics.NORMALIZED_ROOT_MEAN_SQUARED_ERROR,
experiment_name="bike-rentals-automl",
limits={
"timeout_minutes": 30,
"trial_timeout_minutes": 5,
"max_trials": 10,
"max_concurrent_trials": 4,
"enable_early_termination": True
},
training={
"enable_onnx_compatible_models": False
},
compute="cpu-cluster-standard"
)
# Submit
print("Submitting AutoML job...")
job_result = ml_client.jobs.create_or_update(regression_job)
print(f"✅ Job submitted: {job_result.name}")
print(f" URL: {job_result.studio_url}")
# Wait and retrieve the best model
ml_client.jobs.stream(job_result.name)
completed_job = ml_client.jobs.get(job_result.name)
best_run = completed_job.properties.get("best_child_run_id")
print(f"\nBest model: {best_run}")
6. Azure Machine Learning Designer
6.1 Interface and Components
Azure ML Designer = Drag-and-drop interface to visually create ML pipelines.
Key components (modules):
| Category | Key Modules | Description |
|---|---|---|
| Data Input | Import Data, Sample Datasets | Load data |
| Data Transformation | Select Columns, Clean Missing Data, Normalize Data, Split Data | Prepare data |
| Machine Learning | Linear Regression, Boosted Decision Tree, K-Means | Algorithms |
| Model Training | Train Model, Train Clustering Model | Train |
| Model Scoring | Score Model, Assign Data to Clusters | Predict |
| Model Evaluation | Evaluate Model | Measure performance |
6.2 Regression Pipeline (Automobile Prices)
Dataset: Automobile Price Data (built-in sample)
Complete pipeline:
1. Automobile Price Data (Raw) → Source dataset
2. Select Columns in Dataset
→ Exclude: normalized-losses (too many NaN)
3. Clean Missing Data
→ Mode: Remove entire row (remove rows with NaN)
4. Normalize Data
→ Method: MinMax for numerical columns
5. Split Data
→ Fraction: 0.7 (70% train, 30% test)
→ Random seed: 42
6. Linear Regression (Algorithm)
→ Default parameters
7. Train Model
→ Label column: price
8. Score Model
→ Connect: Trained Model + Test Data
9. Evaluate Model
→ Metrics: RMSE, MAE, R²
6.3 Understanding Connections in Designer
Designer uses connection ports:
→ Left port = Input
→ Right port = Output
Train Model has two inputs:
1. Algorithm (left): Comes from the Linear Regression module
2. Data (right): Comes from Split Data (training set)
Score Model has two inputs:
1. Trained model (left): Comes from Train Model
2. Test data (right): Comes from Split Data (test set = right part)
7. Evaluating Regression Models
7.1 The 3 Main Metrics
| Metric | Formula | Unit | Interpretation | Ideal Value |
|---|---|---|---|---|
| MAE (Mean Absolute Error) | Σ|y-ŷ|/n | Same as label | Average absolute error | → 0 |
| RMSE (Root Mean Squared Error) | √(Σ(y-ŷ)²/n) | Same as label | Penalizes large errors more | → 0 |
| R² (R-squared) | 1 - SS_res/SS_tot | Unitless | % of variance explained by the model | → 1 |
7.2 Practical Interpretation
Example: Predicting car prices (in USD)
MAE = 1,500 USD → Average error of $1,500
RMSE = 2,200 USD → Weighted typical error (large errors penalized more)
R² = 0.85 → Model explains 85% of price variance
Interpretation:
• R² > 0.9 → Excellent
• R² > 0.75 → Good
• R² > 0.5 → Acceptable
• R² < 0.5 → Poor model performance
# Calculate regression metrics
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
import numpy as np
import pandas as pd
# Simulate predictions
y_actual = [18000, 25000, 12000, 35000, 22000, 28000]
y_predicted = [17500, 26000, 13500, 33000, 21000, 29500]
mae = mean_absolute_error(y_actual, y_predicted)
rmse = mean_squared_error(y_actual, y_predicted, squared=False)
r2 = r2_score(y_actual, y_predicted)
print("=== Regression Metrics ===")
print(f"MAE : {mae:,.2f} USD")
print(f"RMSE : {rmse:,.2f} USD")
print(f"R² : {r2:.4f}")
print()
r2_interpretation = (
"✅ EXCELLENT" if r2 > 0.9 else
"✅ GOOD" if r2 > 0.75 else
"⚠️ ACCEPTABLE" if r2 > 0.5 else
"❌ INSUFFICIENT"
)
print(f"R² Interpretation: {r2_interpretation}")
print(f"\nIn plain terms:")
print(f" On average, the model is off by ±{mae:,.0f} USD")
print(f" The model explains {r2:.0%} of price variance")
8. Classification Models and Confusion Matrix
8.1 The Confusion Matrix – Demystified!
flowchart TD
CM["Confusion Matrix\n(Binary Classification)"] --> QUAD["4 Cells"]
QUAD --> TP["✅ True Positive (TP)\nPredicted: Positive ✓\nActual: Positive\n\nEx: Predicted Diabetic ✓\nActually is diabetic"]
QUAD --> FP["❌ False Positive (FP)\nPredicted: Positive ✗\nActual: Negative\n\nEx: Predicted Diabetic ✗\nIs NOT diabetic"]
QUAD --> FN["❌ False Negative (FN)\nPredicted: Negative ✗\nActual: Positive\n\nEx: Predicted NOT diabetic ✗\nActually is diabetic"]
QUAD --> TN["✅ True Negative (TN)\nPredicted: Negative ✓\nActual: Negative\n\nEx: Predicted NOT diabetic ✓\nActually is NOT diabetic"]
Matrix structure:
PREDICTED
Positive Negative
ACTUAL Positive | TP | FN |
Negative | FP | TN |
Concrete example (diabetes prediction, 200 patients):
PREDICTED
Diabetic Non-Diabetic
ACTUAL Diabetic | 90 | 10 | ← 100 truly diabetic
Non-Diab.| 5 | 95 | ← 100 non-diabetic
TP = 90 (correctly identified as diabetic)
FP = 5 (false alarm)
FN = 10 (missed diabetics! Dangerous)
TN = 95 (correctly identified as non-diabetic)
8.2 Classification Metrics
# Calculate all classification metrics
from sklearn.metrics import (
accuracy_score, precision_score, recall_score,
f1_score, roc_auc_score, confusion_matrix,
ConfusionMatrixDisplay
)
import numpy as np
import matplotlib.pyplot as plt
# Sample data (diabetes prediction)
y_actual = [1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1]
y_predicted = [1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1]
y_proba = [0.9, 0.1, 0.85, 0.3, 0.15, 0.95, 0.2, 0.7, 0.88, 0.92,
0.05, 0.78, 0.12, 0.82, 0.65, 0.4, 0.91, 0.08, 0.18, 0.87]
# Calculate metrics
accuracy = accuracy_score(y_actual, y_predicted)
precision = precision_score(y_actual, y_predicted)
recall = recall_score(y_actual, y_predicted)
f1 = f1_score(y_actual, y_predicted)
auc = roc_auc_score(y_actual, y_proba)
print("=== Classification Metrics ===\n")
print(f"Accuracy : {accuracy:.4f} → {accuracy:.0%} of predictions are correct")
print(f"Precision : {precision:.4f} → Of predicted positives, {precision:.0%} are true")
print(f"Recall : {recall:.4f} → Of true positives, {recall:.0%} are detected")
print(f"F1-Score : {f1:.4f} → Harmony between Precision and Recall")
print(f"AUC-ROC : {auc:.4f} → Ability to distinguish classes")
# Confusion matrix
cm = confusion_matrix(y_actual, y_predicted)
print(f"\nConfusion Matrix:")
print(f" TP={cm[1,1]}, FP={cm[0,1]}, FN={cm[1,0]}, TN={cm[0,0]}")
# Visualize
fig, ax = plt.subplots(figsize=(6, 5))
disp = ConfusionMatrixDisplay(
confusion_matrix=cm,
display_labels=["Non-Diabetic", "Diabetic"]
)
disp.plot(ax=ax, cmap='Blues')
ax.set_title("Confusion Matrix\n(Diabetes Prediction)")
plt.tight_layout()
plt.savefig("confusion_matrix.png", dpi=150)
print("\nMatrix visualized in: confusion_matrix.png")
8.3 Metrics and Their Formulas
| Metric | Formula | Use When |
|---|---|---|
| Accuracy | (TP+TN) / Total | Balanced classes |
| Precision | TP / (TP+FP) | Minimize false positives (spam) |
| Recall (Sensitivity) | TP / (TP+FN) | Minimize false negatives (serious disease) |
| F1-Score | 2×(P×R)/(P+R) | Balance Precision/Recall |
| AUC-ROC | Area under ROC curve | General evaluation (especially if imbalanced) |
For the exam: Know how to read a confusion matrix and calculate Accuracy, Precision and Recall. These are the most tested metrics.
9. Clustering – Unsupervised Grouping
9.1 K-Means Clustering
K-Means divides data into K groups (clusters) by minimizing intra-cluster distance.
flowchart LR
subgraph "K-Means Algorithm (K=3)"
INIT["1️⃣ Initialize\n3 random centroids"]
ASSIGN["2️⃣ Assign each point\nto nearest centroid"]
UPDATE["3️⃣ Recalculate\ncentroids"]
CONVERGE{"Converged?"}
FINAL["4️⃣ Final clusters"]
end
INIT --> ASSIGN --> UPDATE --> CONVERGE
CONVERGE -->|No| ASSIGN
CONVERGE -->|Yes| FINAL
Pipeline in Azure ML Designer:
Components used:
1. Dataset (Penguin data or similar)
2. Select Columns in Dataset → Select numerical features
3. Clean Missing Data
4. Normalize Data (IMPORTANT for K-Means!)
5. Split Data → 70/30
6. K-Means Clustering
→ Number of centroids: 3 (desired number of clusters)
7. Train Clustering Model
→ Connect: Algorithm + Training Data (ALL columns)
8. Assign Data to Clusters
→ Connect: Trained Model + Test Data
9. Evaluate Clustering Model
→ Metrics: Silhouette Score, Inertia
Exam note: For Train Clustering Model, connect all columns (no specific label like regression/classification).
9.2 Interpreting Clustering Results
# K-Means Clustering and interpretation
from sklearn.cluster import KMeans
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import silhouette_score
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Penguin data
df = pd.DataFrame({
"bill_length": [39.1, 39.5, 40.3, 36.7, 39.3, 38.9, 45.0, 46.5, 46.7, 48.7],
"bill_depth": [18.7, 17.4, 18.0, 19.3, 20.6, 17.8, 13.2, 14.6, 15.3, 14.1],
"flipper_length": [181, 186, 195, 193, 190, 181, 210, 211, 219, 222],
"body_mass": [3750, 3800, 3250, 3450, 3650, 3625, 4200, 4500, 5000, 5850]
})
# Normalize (CRITICAL for K-Means)
scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(df)
# Find optimal K (elbow method)
inertias = []
silhouettes = []
K_range = range(2, 7)
for k in K_range:
km = KMeans(n_clusters=k, random_state=42, n_init=10)
labels = km.fit_predict(X_scaled)
inertias.append(km.inertia_)
silhouettes.append(silhouette_score(X_scaled, labels))
print("Silhouette Scores by K:")
for k, sil in zip(K_range, silhouettes):
bar = "█" * int(sil * 20)
print(f" K={k}: {sil:.3f} {bar}")
# Train with optimal K
optimal_k = K_range[silhouettes.index(max(silhouettes))]
km_final = KMeans(n_clusters=optimal_k, random_state=42, n_init=10)
df["cluster"] = km_final.fit_predict(X_scaled)
print(f"\n✅ Optimal K: {optimal_k} clusters")
print(f" Silhouette Score: {max(silhouettes):.3f}")
# Profile each cluster
print("\n=== Cluster Profiles ===")
for cluster_id in range(optimal_k):
cluster_data = df[df["cluster"] == cluster_id]
print(f"\nCluster {cluster_id} (n={len(cluster_data)}):")
for col in df.columns[:-1]:
print(f" {col}: {cluster_data[col].mean():.1f}")
10. Deep Learning
10.1 Deep Learning Concepts for the Exam
flowchart TD
DL["Deep Learning"] --> WHEN["When to use it"]
DL --> HOW["How it works"]
DL --> AZURE["On Azure"]
WHEN --> W1["Unstructured data\n(Images, Text, Audio)"]
WHEN --> W2["Large data volume\n(Thousands/millions of examples)"]
WHEN --> W3["Complex tasks\n(Vision, NLP, Speech)"]
HOW --> H1["Neuron layers\n(Input → Hidden → Output)"]
HOW --> H2["Automatically learns\nfeatures"]
HOW --> H3["Backpropagation\n(Adjust weights)"]
AZURE --> A1["Azure AI Vision\n(Images)"]
AZURE --> A2["Azure AI Speech\n(Audio)"]
AZURE --> A3["Azure AI Language\n(Text)"]
AZURE --> A4["Azure OpenAI\n(LLMs)"]
What you need to know for the exam:
- Deep Learning is a subset of Machine Learning
- Uses multi-layer artificial neural networks
- Best for unstructured data (images, audio, text)
- Requires lots of data and computing power (GPU)
- Azure offers pre-built services based on DL (no need to code networks)
11. Inference Pipelines and Deployment
11.1 Training Pipeline vs. Inference Pipeline
flowchart LR
subgraph "Training Pipeline"
direction LR
TD["Training Data"] --> PREP_T["Preprocessing"] --> ALG["Algorithm"] --> TRAIN["Train Model"] --> SCORE_T["Score Model"] --> EVAL["Evaluate Model"]
end
subgraph "Inference Pipeline (Deployment)"
direction LR
WS_IN["Web Service Input\n(New data)"] --> PREP_I["Preprocessing\n(Same as training)"] --> TRAINED["Trained Model\n(Saved)"] --> SCORE_I["Score Model"] --> WS_OUT["Web Service Output\n(Predictions)"]
end
Key differences:
- The inference pipeline removes training (model already trained)
- The inference pipeline removes evaluation (just want to predict)
- The inference pipeline adds Web Service Input/Output
- The training pipeline becomes an inference pipeline via “Create inference pipeline”
11.2 Deployment on Azure Container Instance vs. AKS
| Azure Container Instance (ACI) | Azure Kubernetes Service (AKS) | |
|---|---|---|
| Use | Testing, development | Production |
| Scalability | Low | Very high |
| Cost | Low | Higher |
| Complexity | Simple | More complex |
| SLA | Not guaranteed | 99.9% |
| When to choose | Testing/small deployments | Large-scale production |
For the exam: If the question mentions “test” or “small deployment” → ACI. Otherwise → AKS is the recommended choice for production.
# Deployment via Azure ML SDK (simplified for exam context)
from azure.ai.ml import MLClient
from azure.ai.ml.entities import (
ManagedOnlineEndpoint, ManagedOnlineDeployment
)
from azure.identity import DefaultAzureCredential
import os
ml_client = MLClient(
credential=DefaultAzureCredential(),
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"],
resource_group_name=os.environ["AZURE_RESOURCE_GROUP"],
workspace_name=os.environ["AZURE_ML_WORKSPACE"]
)
# Create the endpoint
endpoint = ManagedOnlineEndpoint(
name="income-prediction-endpoint",
auth_mode="key"
)
ml_client.online_endpoints.begin_create_or_update(endpoint).result()
# Deploy the model
deployment = ManagedOnlineDeployment(
name="v1",
endpoint_name="income-prediction-endpoint",
model=ml_client.models.get("income-classifier", version="1"),
instance_type="Standard_DS2_v2",
instance_count=1
)
ml_client.online_deployments.begin_create_or_update(deployment).result()
# Route traffic
endpoint.traffic = {"v1": 100}
ml_client.online_endpoints.begin_create_or_update(endpoint).result()
print("✅ Model deployed!")
# The endpoint can now be called via REST API
12. Practical Implementation with Python and SDK
12.1 Complete ML Pipeline (End-to-End)
# Complete ML pipeline: Regression on bike rentals with Azure ML SDK
import pandas as pd
import numpy as np
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
import mlflow
import joblib
import os
def prepare_data(csv_path: str) -> tuple:
"""Load, clean and prepare data."""
# Load
df = pd.read_csv(csv_path)
print(f"Dataset loaded: {df.shape}")
# Cleaning
df = df.dropna()
df = df.drop_duplicates()
# Simple feature engineering
df["is_weekend"] = df["day"].isin([6, 7]).astype(int)
# Define features and label
feature_cols = [c for c in df.columns if c != "rentals"]
X = df[feature_cols]
y = df["rentals"]
# Split
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
# Normalization
scaler = MinMaxScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
return X_train_scaled, X_test_scaled, y_train, y_test, scaler, feature_cols
def train_and_evaluate(X_train, X_test, y_train, y_test) -> dict:
"""Train the model and return metrics."""
mlflow.set_experiment("bike-rentals-fundamentals")
with mlflow.start_run(run_name="GBM-v1"):
# Parameters
params = {
"n_estimators": 200,
"learning_rate": 0.05,
"max_depth": 4
}
mlflow.log_params(params)
# Train
model = GradientBoostingRegressor(**params, random_state=42)
model.fit(X_train, y_train)
# Predict
y_pred_train = model.predict(X_train)
y_pred_test = model.predict(X_test)
# Metrics
metrics = {
"train_mae": mean_absolute_error(y_train, y_pred_train),
"train_rmse": mean_squared_error(y_train, y_pred_train, squared=False),
"train_r2": r2_score(y_train, y_pred_train),
"test_mae": mean_absolute_error(y_test, y_pred_test),
"test_rmse": mean_squared_error(y_test, y_pred_test, squared=False),
"test_r2": r2_score(y_test, y_pred_test)
}
for k, v in metrics.items():
mlflow.log_metric(k, v)
print("\n=== Model Metrics ===")
print(f"Train R²: {metrics['train_r2']:.4f}")
print(f"Test R²: {metrics['test_r2']:.4f}")
print(f"Test MAE: {metrics['test_mae']:.2f} rentals")
print(f"Test RMSE:{metrics['test_rmse']:.2f} rentals")
verdict = (
"✅ EXCELLENT" if metrics["test_r2"] > 0.9 else
"✅ GOOD" if metrics["test_r2"] > 0.75 else
"⚠️ ACCEPTABLE"
)
print(f"Verdict: {verdict}")
# Save
mlflow.sklearn.log_model(model, "model")
return metrics, model
def evaluate_feature_importance(model, feature_names: list) -> pd.DataFrame:
"""Display the most important features."""
importances = pd.DataFrame({
"feature": feature_names,
"importance": model.feature_importances_
}).sort_values("importance", ascending=False)
print("\n=== Feature Importance (Top 5) ===")
for _, row in importances.head(5).iterrows():
bar = "█" * int(row["importance"] * 50)
print(f" {row['feature']:15}: {row['importance']:.3f} {bar}")
return importances
# Usage
# Simulate bike data
np.random.seed(42)
n = 500
bike_data = pd.DataFrame({
"season": np.random.randint(1, 5, n),
"month": np.random.randint(1, 13, n),
"day": np.random.randint(1, 8, n),
"hour": np.random.randint(0, 24, n),
"temp": np.random.uniform(0, 40, n),
"humidity": np.random.uniform(20, 95, n),
"wind": np.random.uniform(0, 50, n),
"rentals": np.random.randint(50, 900, n)
})
bike_data.to_csv("bike_rentals.csv", index=False)
X_train, X_test, y_train, y_test, scaler, features = prepare_data("bike_rentals.csv")
metrics, trained_model = train_and_evaluate(X_train, X_test, y_train, y_test)
importances = evaluate_feature_importance(trained_model, features)
13. Exam Tips and Common Pitfalls
13.1 Common Pitfall Table
| Pitfall | Clarification |
|---|---|
| R² = 1 always good? | NO! R² = 1 may indicate overfitting (memorization) |
| Accuracy = best metric | NOT ALWAYS. For imbalanced classes → AUC or F1 |
| More algorithms = better | NO. Start simple (Linear Regression), add complexity if needed |
| AutoML or Designer? | AutoML = automatic (best model auto-selected). Designer = manual control |
| AKS vs ACI | Test/dev → ACI. Production → AKS |
| Always normalize? | Not mandatory. Use when features have very different scales |
| Train set = evaluate model | NO! Always evaluate on the TEST set (unseen data) |
| K-Means in Designer | The ONLY clustering algorithm available in Designer |
13.2 Typical Exam Questions
Q1: You want to predict a house price based on area, location, and age. What type of ML?
A: Regression – predicting a numeric value (the price).
Q2: A bank wants to automatically detect fraud (fraud/non-fraud). What type of ML?
A: Binary classification – two possible classes.
Q3: A company wants to group its customers without prior labels. What type of ML?
A: Clustering – unsupervised, no labels.
Q4: Your classification model has: TP=90, FP=5, FN=10, TN=95. What is the Precision?
A: Precision = TP/(TP+FP) = 90/(90+5) = 90/95 ≈ 94.7%
Q5: What is the recommended choice for deploying a model in production with high availability?
A: Azure Kubernetes Service (AKS).
Q6: Difference between AutoML and Designer?
A: AutoML = automatic, tries all algorithms, chooses the best. Designer = drag-and-drop manual, you choose the algorithm.
13.3 AI-900 Exam Checklist – ML Section
✅ Understand the difference between Regression / Classification / Clustering
✅ Know how to read and calculate regression metrics (RMSE, MAE, R²)
✅ Know how to read a Confusion Matrix and calculate Precision, Recall, F1
✅ Understand Train/Test Split and why it's necessary
✅ Know when to use AutoML vs Designer
✅ Know when to use ACI vs AKS
✅ Understand the role of preprocessing (cleaning, normalization)
✅ Know the concept of inference pipeline
✅ Know that Deep Learning is a subset of ML for unstructured data
✅ Know the terminology: dataset, feature, label, algorithm, model
14. Summary and Key Points
14.1 Condensed Overview
flowchart TD
ML["Machine Learning\n(Predict unknown values)"] --> SUPERVISED["Supervised\n(Known labels)"]
ML --> UNSUPERVISED["Unsupervised\n(No labels)"]
ML --> DL2["Deep Learning\n(Unstructured data)"]
SUPERVISED --> REG2["Regression\n→ Numeric value\n→ Metrics: RMSE, R²"]
SUPERVISED --> CLASS2["Classification\n→ Category\n→ Metrics: Accuracy, F1, AUC"]
UNSUPERVISED --> CLUST2["Clustering\n→ Similar groups\n→ K-Means in Designer"]
REG2 --> TOOLS["Azure Tools"]
CLASS2 --> TOOLS
CLUST2 --> TOOLS
TOOLS --> AUTOML2["AutoML\n(Automatic)"]
TOOLS --> DESIGNER2["Designer\n(Drag-and-drop)"]
TOOLS --> SDK2["Python SDK\n(Code)"]
14.2 Final Summary Table
| Type | Example | Designer Algorithm | Metrics |
|---|---|---|---|
| Regression | Predict car price | Linear Regression, Boosted DT | RMSE, MAE, R² |
| Binary Classification | Fraud yes/no | Two-Class LR, Two-Class DT | Accuracy, Precision, Recall, F1, AUC |
| Multi-class Classification | Sentiment type | Multiclass Decision Forest | Accuracy, F1 macro |
| Clustering | Segment customers | K-Means (only option) | Silhouette Score |
| Deep Learning | Recognize images | (Azure prebuilt services) | Case-dependent |
15. Glossary
| Term | Definition |
|---|---|
| Accuracy | (TP+TN)/(TP+TN+FP+FN) – % of correct predictions |
| AKS | Azure Kubernetes Service – ML deployment in production |
| ACI | Azure Container Instance – ML deployment for testing |
| Algorithm | Mathematical method for learning from data |
| AutoML | Automated Machine Learning – automatic best algorithm selection |
| AUC-ROC | Area Under the Curve – overall classification measure |
| Cleaning | Data cleaning (removing NaN, duplicates…) |
| Classification | Predict a category an element belongs to |
| Clustering | Group similar elements without labels (unsupervised) |
| Confusion Matrix | TP/FP/FN/TN table to evaluate a classification model |
| Dataset | Collection of data organized in rows and columns |
| Deep Learning | ML subset using deep neural networks |
| Designer | Azure ML drag-and-drop interface for visual pipelines |
| F1-Score | Harmony between Precision and Recall: 2×(P×R)/(P+R) |
| False Negative (FN) | Positive case predicted negative (Type II error) |
| False Positive (FP) | Negative case predicted positive (Type I error) |
| Feature | Input column of an ML model (predictor variable) |
| Inference Pipeline | Deployment pipeline using an already trained model |
| K-Means | Unsupervised clustering algorithm with K centroids |
| Label | Value to predict (target column) |
| MAE | Mean Absolute Error – average absolute error |
| Model | File resulting from training containing learned patterns |
| Normalization | Bring features to the same scale (typically 0-1) |
| Overfitting | Model memorizing training data, poor generalization |
| Precision | TP/(TP+FP) – quality of positive predictions |
| Recall | TP/(TP+FN) – ability to find all positives |
| R² | Coefficient of determination (0 to 1) – explained variance |
| Regression | Predict a continuous numeric value |
| RMSE | Root Mean Squared Error |
| Split Data | Dividing the dataset into training and test sets |
| Supervised Learning | Learning with known labels |
| Training | Process of training a model on historical data |
| True Positive (TP) | Positive case correctly predicted as positive |
| True Negative (TN) | Negative case correctly predicted as negative |
| Underfitting | Model too simple to capture patterns |
| Unsupervised Learning | Learning without labels (clustering) |
Additional resources:
Extended Table of Contents
- Introduction to Machine Learning
- Types of Machine Learning
- Azure Tools for Machine Learning
- Data Preparation
- Demo: Automated ML — Bike Rental Regression
- Demo: Machine Learning Designer — Regression Pipeline
- Classification Models
- Demo: Classification — Income Prediction
- Demo: Inference Pipeline and Model Deployment
- Clustering Models
- AI-900 Exam Tips
- Summary and Next Steps
1. Introduction to Machine Learning
Machine learning is a technique that uses mathematics and statistics to create a model capable of predicting unknown values.
Concrete example: A car dealership wants to estimate the price of a car based on engine displacement, mileage, etc. Using historical data (prices + characteristics of previously sold cars), you train a model that can predict the price of a new car.
Basic terminology:
| Term | Definition |
|---|---|
| Dataset | Collection of historical data, typically in tabular format (rows and columns) |
| Features | Input variables (e.g., engine size, mileage) |
| Label | The value to predict (e.g., the price) |
| Model | File trained with data and an algorithm to recognize patterns |
Complete machine learning flow:
Historical dataset
(features + label)
│
▼
┌─────────────────┐
│ ML Platform │ ← Chosen algorithm
│ (Azure ML) │
└─────────────────┘
│
▼
Trained model
│
▼
Deployment
│
▼
New data → PREDICTIONS
(features only)
2. Types of Machine Learning
┌─────────────────────────────────────────────────────────────┐
│ MACHINE LEARNING │
│ │
│ ┌─────────────────┐ ┌──────────────────────────────┐ │
│ │ SUPERVISED │ │ UNSUPERVISED │ │
│ │ │ │ │ │
│ │ • Regression │ │ • Clustering │ │
│ │ • Classification│ │ (grouping elements) │ │
│ │ │ │ │ │
│ │ Features + Label│ │ Features only │ │
│ │ → Predict │ │ → Group │ │
│ └─────────────────┘ └──────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ DEEP LEARNING (subset of ML) │ │
│ │ Artificial neural networks │ │
│ │ • Images, videos, audio, text │ │
│ │ • Trains itself on large quantities of data │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
2.1 Regression
Objective: Predict a numeric value (the label is a number).
Examples:
- Predict the price of a car from its characteristics
- Predict the number of bike rentals per day based on weather
Evaluation metrics:
| Metric | Description | Interpretation |
|---|---|---|
| R² Score | Correlation measure (0 to 1) | Closer to 1 = better |
| Root Mean Squared Error (RMSE) | Measures prediction errors | Smaller = better |
| Normalized RMSE | Normalized RMSE | Smaller = better |
2.2 Classification
Objective: Predict a category or class an element belongs to.
Two subtypes:
| Type | Number of classes | Example |
|---|---|---|
| Binary classification | 2 (0 or 1) | Diabetic or not, high or low risk |
| Multi-class classification | 3+ | Mood: happy/sad/angry/anxious |
Concrete example (binary): A hospital wants to predict if a patient is diabetic based on:
- Features: age, BMI, blood pressure, plasma index
- Label: 0 = non-diabetic, 1 = diabetic
Learning type: Supervised (data with both features AND known label)
2.3 Clustering (Unsupervised)
Objective: Group similar elements into clusters based on their features.
Key difference: No known label — not trying to predict, trying to group.
Example: Group flowers by petal count, leaf size, etc.
Algorithm in Azure ML Designer: K-Means Clustering (only clustering option)
Clustering vs. Regression Pipeline:
Clustering: Regression:
- Select Columns - Select Columns
- Clean Missing Data - Clean Missing Data
- Normalize Data - Normalize Data
- Split Data - Split Data
- K-Means Clustering (algo) - Linear Regression (algo)
- Train Clustering Model - Train Model (label = value)
- Assign Data to Clusters - Score Model
- Evaluate Model - Evaluate Model
2.4 Deep Learning
Machine Learning vs. Deep Learning comparison:
| Aspect | Classical Machine Learning | Deep Learning |
|---|---|---|
| Data volume | Small to medium | Large (required) |
| Computing power | Standard computer | High-performance machines |
| Features | Defined by user | Learned automatically |
| Training time | Minutes to a few hours | Very long |
| Output | Numeric value or class | Text, sound, image, score, etc. |
Deep Learning use cases:
- Identifying patterns in unstructured data (images, video, sound, text)
- Object detection
- Image caption generation
- Speech and text translation with high accuracy
3. Azure Tools for Machine Learning
Azure Machine Learning Studio
│
├── Azure Automated Machine Learning
│ • Dataset → Select label → Compute cluster
│ • Azure chooses the best algorithm automatically
│ • Results in ~1 hour
│
└── Azure Machine Learning Designer
• Drag-and-drop interface
• Pre-packaged modules
• More flexibility (cleaning, normalization, split, etc.)
• Full control over the pipeline
3.1 Azure Automated Machine Learning
Advantages: Fast, doesn’t require advanced ML expertise Disadvantages: Less control over processing steps
Steps:
- Create/import a dataset
- Choose task type (Regression, Classification, NLP, Computer Vision)
- Select the label (column to predict)
- Configure compute cluster
- Set a timeout (e.g., 15 minutes)
- Submit the job and wait for results
Deployment: To an Azure Container Instance (ACI) via Deploy → Web service button
3.2 Azure Machine Learning Designer
Advantages: Full control, visual modules, more preprocessing options Interface: Drag-and-drop canvas with connectable modules
4. Data Preparation
4.1 Cleaning
Problem: Rows with missing data or null values (NaN).
Solution: Clean Missing Data module
- Remove entire rows with missing values
- Or replace missing values with a meaningful value
4.2 Normalization
Problem: Columns with very different scales can bias the model.
Example:
- Column “Engine Size”: 0 to 2000
- Column “Gas Mileage”: 0 to 60
Solution: Normalize Data module — brings all values between 0 and 1
- Engine Size 1500 → 0.75
- Gas Mileage 50 → 0.90
4.3 Train/Test Split
Standard practice: Split the dataset into two subsets:
- 70% for training (Train) → fed to the Train Model module
- 30% for validation (Validate) → fed to the Score Model module
Module: Split Data → parameter “Fraction of rows in first output dataset” = 0.7
5. Demo: Automated ML — Bike Rental Regression
Objective: Predict the number of bike rentals per day (regression).
Dataset: Microsoft bike rentals — columns: day, month, year, season, holiday, temperature, humidity, wind speed, rentals (label).
Key steps:
- Azure ML Studio → Automated ML → New job
- Task type: Regression
- Create dataset “bikerentals” from URL (Tabular format)
- Feature selection: remove
atempcolumn (redundant) - Target column: rentals
- Configure limits: Experiment timeout = 15 minutes, enable “Early termination”
- Compute type: Compute cluster (dual core VM)
- Submit job
Results:
- Best model: VotingEnsemble (ensemble of several algorithms)
- Normalized RMSE: error measure (lower = better)
- R² Score: closer to 1 = better
Endpoint testing:
- After deployment on Azure Container Instance
- Endpoints → Test → Enter a row from the dataset
- Actual value: 331 rentals → Model prediction: 380 rentals (reasonable result)
6. Demo: Machine Learning Designer — Regression Pipeline
Objective: Predict car price (Automobile Price dataset).
Complete pipeline:
[Automobile price data (Raw)]
│
▼
[Select Columns in Dataset]
Exclude: normalized-losses (NaN values)
│
▼
[Clean Missing Data]
Mode: Remove entire row
Columns: All columns
│
▼
[Split Data]
Fraction: 0.7 (70% train, 30% validation)
│
┌──────┴──────┐
▼ ▼
70% 30%
│ │
└──────┬──────┘
│
[Linear Regression] ───► [Train Model]
Label: price
│
[Score Model]
│
[Evaluate Model]
Results: Compare “price” (actual value) vs “Scored Labels” (predicted value) in Score Model preview.
7. Classification Models
7.1 The Confusion Matrix
The confusion matrix is the primary tool for evaluating a classification model.
Example with the Diabetes dataset (2 classes):
ACTUAL VALUES
Diabetic (1) │ Non-diabetic (0)
──────────────┼──────────────────
PREDICTIONS 1 │ True Positive│ False Positive
(Diabetic) │ (TP) │ (FP)
───┼───────────────┼──────────────────
0 │ False Negative│ True Negative
(Non-diab.) │ (FN) │ (TN)
Definitions:
- True Positive (TP): Predicted diabetic + actually diabetic ✓
- True Negative (TN): Predicted non-diabetic + actually non-diabetic ✓
- False Positive (FP): Predicted diabetic BUT actually non-diabetic ✗
- False Negative (FN): Predicted non-diabetic BUT actually diabetic ✗
Example exam question: “How many people are diabetic but the model predicted they were not?” → Answer: look at False Negative (FN) = “Diabetic (1)” column + “Non-diabetic (0)” row
Note: For 3 classes → 3×3 matrix; for 4 classes → 4×4 matrix. The AI-900 exam focuses on 2×2 matrices.
7.2 Classification Pipeline
Differences from the regression pipeline:
| Aspect | Regression | Classification |
|---|---|---|
| Algorithm | Linear Regression | Two-Class Logistic Regression |
| Label | Numeric value (e.g., price) | Category (e.g., income ≤50k or >50k) |
| Metrics | R², RMSE | Confusion Matrix, ROC Curve, Precision-Recall |
According to the Microsoft Algorithm Cheat Sheet:
- 2 classes → Two-Class Logistic Regression (fast training, linear)
- 3+ classes → Other multi-class algorithms
7.3 Inference Pipeline and Deployment
A training pipeline is used to train the model. To make it usable in production, you create an inference pipeline.
Types of inference pipeline:
| Type | Usage |
|---|---|
| Real-time | Few simultaneous predictions |
| Batch | Large number of predictions at once |
Conversion steps:
- After running the training pipeline → Create Inference Pipeline → Real-time
- A Web Service Input module is automatically added
- A Web Service Output module is automatically added
- Delete the Evaluate Model module (not needed for prediction)
- Modify Select Columns to exclude the label column (otherwise the model expects the result to predict!)
- Submit and deploy
Deployment:
- Azure Kubernetes Service (AKS): For production scenarios or when the test doesn’t specifically mention ACI
- Azure Container Instance (ACI): For tests or small deployments
Access: Development team can access via REST API + authentication key
8. Demo: Classification — Income Prediction
Objective: Predict whether income is ≤ $50k or > $50k (binary classification).
Dataset: Census Income — columns: age, employment, education, occupation, race, sex, capital-gain, capital-loss, income (label).
Pipeline:
[Census Income Dataset]
│
▼
[Select Columns in Dataset]
Exclude: race, sex (eliminate potential biases)
│
▼
[Clean Missing Data]
Mode: Remove entire row
Exclude: income (label column — don't clean it)
│
▼
[Normalize Data]
Columns: fnlwgt, capital-gain, capital-loss (high values)
│
▼
[Split Data] → 70% train / 30% validation
│
┌──────┴──────┐
[Two-Class Logistic Regression]
│
[Train Model] → Label: income
│
[Score Model]
│
[Evaluate Model]
Results in Evaluate Model:
- ROC Curve (Receiver Operating Characteristic) graph
- Precision-Recall Curve graph
- Confusion Matrix with the 4 quadrants
9. Demo: Inference Pipeline and Model Deployment
Steps from the training pipeline (income classification):
- 3 dots → “Create inference pipeline” → “Real-time inference pipeline”
- Fix the Web Service Input link: connect it to the Apply Transformation module
- In Select Columns: exclude the
incomecolumn (otherwise the API expects this value which we want to predict) - Remove the Evaluate Model module
- Configure & Submit → New experiment “income”
- After execution → Deploy
- Name:
incomeendpoint| Compute type: Azure Container Instance - CPU: 1 | Memory: 1 (to avoid abuse triggers in the test environment)
Testing from Endpoints:
- Endpoints → incomeendpoint → Test tab
- Pre-filled test data available
- Results: “Scored Labels” → model predictions
10. Clustering Models
Specific training module: Train Clustering Model (replaces Train Model) Only available algorithm: K-Means Clustering
Key parameter: Number of centroids = initial number of clusters
Clustering pipeline:
[Penguin dataset: BillLength, Depth, FlipperLength, BodyMass, Species]
│
[Select Columns] → [Clean Missing Data] → [Normalize Data]
│
[Split Data] → 70% train / 30% validation
│
┌──────┴──────┐
[K-Means Clustering]
│
[Train Clustering Model]
Columns: All columns (no label to predict)
│
[Assign Data to Clusters] ← 30% validation data
│
[Evaluate Model]
Results from Assign Data to Clusters: “Cluster Assignment” column = 0, 1, or 2 (based on number of clusters)
Exam note: Clustering evaluation metrics are not required for the AI-900. Only regression metrics (R², RMSE) and classification metrics (Confusion Matrix) need to be known.
11. AI-900 Exam Tips
Essential Terminology
| Concept | Definition to remember |
|---|---|
| Dataset | Collection of historical data |
| Features | Input variables |
| Label | Value to predict |
| Model | File trained to recognize patterns |
| Training pipeline | To train the model |
| Inference pipeline | To deploy and use the model |
Differences: Automated ML vs. Designer
| Criterion | Azure Automated ML | Azure ML Designer |
|---|---|---|
| Control level | Low (automatic) | High (manual) |
| Required expertise | Minimal | Moderate |
| Setup time | Very fast | Longer |
| Flexibility | Limited | High |
| Use when… | Quick start, exploration | Precise pipeline control |
ML Types to Recognize on the Exam
| Scenario | ML Type |
|---|---|
| Predict a number (price, quantity, temperature) | Regression |
| Predict a category (spam/not spam, diabetic/not) | Classification |
| Group similar elements | Clustering |
| Identify patterns in images/sound/text | Deep Learning |
Model Deployment
| Service | When to use |
|---|---|
| Azure Kubernetes Service (AKS) | Production, outside testing context (default for exam) |
| Azure Container Instance (ACI) | Tests, small deployments (if specifically mentioned) |
The Confusion Matrix (key points for the exam)
Predicted Positive Predicted Negative
Actual Positive True Positive False Negative
Actual Negative False Positive True Negative
12. Summary and Next Steps
What you now know:
- Machine learning = mathematics/statistics to create predictive models
- Regression = predict a numeric value
- Classification = predict a category (Binary or Multi-class)
- Clustering = group similar elements (unsupervised)
- Deep Learning = patterns in unstructured data (images, sound, text)
- Azure Automated ML = quick start without writing code
- Azure ML Designer = visual pipelines with full control
Next course in the AI-900 series:
Microsoft Azure AI Fundamentals (AI-900): Computer Vision Workloads on Azure
Documentation resources:
13. Detailed Demo: Income Prediction (Census Income)
13.1 Context and Objective
Dataset: Census Income (Adult Dataset) — US census data.
Objective: Predict whether a person earns ≤ $50,000 or > $50,000 per year.
ML Type: Binary classification (two possible outcomes)
Dataset columns:
| Column | Type | Role |
|---|---|---|
| age | Numeric | Feature |
| workclass | Categorical | Feature |
| fnlwgt | Numeric | Feature (statistical weight — normalize) |
| education | Categorical | Feature |
| education-num | Numeric | Feature |
| marital-status | Categorical | Feature |
| occupation | Categorical | Feature |
| relationship | Categorical | Feature |
| race | Categorical | Exclude (ethical bias) |
| sex | Categorical | Exclude (ethical bias) |
| capital-gain | Numeric | Feature (normalize — high values) |
| capital-loss | Numeric | Feature (normalize — high values) |
| hours-per-week | Numeric | Feature |
| native-country | Categorical | Feature |
| income | Categorical | Label (≤50K or >50K) |
13.2 Complete Pipeline with Mermaid
flowchart TD
A["Census Income Dataset"] --> B["Select Columns in Dataset\n❌ Exclude: race, sex"]
B --> C["Clean Missing Data\n Mode: Remove entire row\n Exclude income column"]
C --> D["Normalize Data\n Columns: fnlwgt, capital-gain, capital-loss\n Method: MinMax"]
D --> E["Split Data\n Fraction: 0.7"]
E -->|"70% Training"| F["Two-Class Logistic Regression\n Tolerance: 1E-07\n Max iterations: 100"]
E -->|"30% Validation"| G["Score Model"]
F --> H["Train Model\n Label: income"]
H --> G
G --> I["Evaluate Model\n Confusion Matrix\n ROC Curve\n Precision-Recall"]
13.3 Detail of Each Module
Module: Select Columns in Dataset
- Role: Remove
raceandsexcolumns to eliminate discriminatory biases - On the exam: may also need to remove redundant or irrelevant columns
Module: Clean Missing Data
- Mode:
Remove entire row - Important: Exclude the label column
incomefrom cleaning (otherwise rows with label are deleted) - If you clean the label too, you lose valuable training data
Module: Normalize Data
- Target columns:
fnlwgt(values >100,000),capital-gain(0 to 99,999),capital-loss(0 to 4,356) - These columns have scales far exceeding other features (age: 17-90, hours/week: 1-99)
- Normalization brings everything to 0-1 → model isn’t “dominated” by large values
Module: Two-Class Logistic Regression
- Algorithm recommended by the Microsoft Algorithm Cheat Sheet for fast binary classification
- Linear model → fast training
- Suitable when the relationship between features and label is approximately linear
Module: Train Model
- Left connection: algorithm (Two-Class Logistic Regression)
- Right connection: 70% of data (left split)
- Key parameter: choose label column =
income
Module: Score Model
- Left connection: trained model (Train Model)
- Right connection: 30% of data (right split)
- Output: dataset with 2 new columns →
Scored LabelsandScored Probabilities
13.4 Results and Metrics
In Evaluate Model, three important graphs:
┌─────────────────────────────────────────────────────────────────┐
│ 1. CONFUSION MATRIX │
│ │
│ Predicted ≤50K Predicted >50K │
│ Actual ≤50K TN FP │
│ Actual >50K FN TP │
│ │
│ 2. ROC CURVE 3. PRECISION-RECALL CURVE │
│ AUC → closer to 1 Shows the trade-off between │
│ = better Precision and Recall │
└─────────────────────────────────────────────────────────────────┘
14. Detailed Demo: Inference Pipeline and Deployment
14.1 Context: From Training to Deployment
A training pipeline is used to create the model. For applications to use this model, it must be converted into an inference pipeline and then deployed.
flowchart LR
A["Training Pipeline\n(Training)"] -->|"Create inference pipeline"| B["Inference Pipeline\n(Deployment)"]
B -->|"Deploy"| C["Web Service\n(REST API)"]
C -->|"HTTP POST"| D["Client application\n(JSON results)"]
14.2 Conversion Steps
Step 1 — Create the inference pipeline:
- From the executed training pipeline → click the 3 dots
...→Create inference pipeline→Real-time inference pipeline - Azure automatically adds a Web Service Input module and a Web Service Output module
Step 2 — Fix the Web Service Input link:
Common issue: The Web Service Input module sometimes connects to the wrong place (directly to Score Model instead of Apply Transformation).
Document generated for AI-900 Azure AI Fundamentals – Fundamental Principles of Machine Learning on Azure
Search Terms
ai-900 · fundamental · principles · machine · azure · ai · services · artificial · intelligence · generative · pipeline · exam · classification · deployment · regression · clustering · designer · inference · automated · automl · confusion · deep · matrix · metrics