Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on. You've got this! π
Types of Machine Learning
There are three fundamental paradigms in ML. Supervised Learning uses labeled training data (you know the answer). Unsupervised Learning finds hidden patterns in unlabeled data. Reinforcement Learning trains agents via rewards from environment interaction. 90% of production ML is supervised learning - that is the primary focus of this course.
ML Paradigms with Examples
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.cluster import KMeans
from sklearn.datasets import make_classification, make_blobs
# βββββββββββββββββββββββββββββ
# 1. SUPERVISED LEARNING
# βββββββββββββββββββββββββββββ
# You have: features (X) AND known labels (y)
# Goal: learn a mapping X -> y
# Regression example: predict house prices
house_data = np.array([[1200, 2], [1500, 3], [1800, 3], [2200, 4], [2800, 5]]) # sqft, bedrooms
prices = np.array([250000, 310000, 380000, 450000, 590000]) # target labels
reg = LinearRegression()
reg.fit(house_data, prices)
new_house = np.array([[2000, 3]])
print(f"Predicted price: ${reg.predict(new_house)[0]:,.0f}")
# Classification example: predict if loan will default (0=no, 1=yes)
X, y = make_classification(n_samples=1000, n_features=10, random_state=42)
# X: features (income, credit score, debt ratio...)
# y: 0 (no default) or 1 (default)
print(f"Classification dataset: {X.shape} features, classes={np.unique(y)}")
# βββββββββββββββββββββββββββββ
# 2. UNSUPERVISED LEARNING
# βββββββββββββββββββββββββββββ
# You have: features (X) only - NO labels
# Goal: discover hidden structure in data
# Clustering: group customers by behavior
X_customers, _ = make_blobs(n_samples=300, centers=4, random_state=42)
kmeans = KMeans(n_clusters=4, random_state=42, n_init="auto")
cluster_labels = kmeans.fit_predict(X_customers)
print(f"Customers assigned to clusters: {np.bincount(cluster_labels)}")
# βββββββββββββββββββββββββββββ
# 3. REINFORCEMENT LEARNING (overview)
# βββββββββββββββββββββββββββββ
# Agent takes actions in environment, receives rewards
# Covered in the AI course (DeepMind, OpenAI Gym)
# Real-world: game playing, robotics, trading bots
# SUMMARY TABLE
learning_types = {
"Supervised": {"input": "X + y (labeled)", "output": "Predictions", "examples": "Fraud detection, price prediction"},
"Unsupervised": {"input": "X only", "output": "Structure/groups", "examples": "Customer segments, anomaly detection"},
"Reinforcement": {"input": "State + rewards", "output": "Optimal policy", "examples": "Game AI, robotic control"},
}
print("\nML Paradigm Summary:")
for name, info in learning_types.items():
print(f" {name:15s}: Input={info['input']:20s} | Examples={info['examples']}")Tip
Tip
Practice Types of Machine Learning in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Labeled data β supervised, no labels β unsupervised, rewards β RL
Practice Task
Note
Practice Task - (1) Write a working example of Types of Machine Learning from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Types of Machine Learning is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready ml code.