Types of Machine Learning
Learn the four major types of Machine Learning — Supervised, Unsupervised, Semi-Supervised and Reinforcement Learning — with simple explanations, diagrams and real-world use cases.
High-level Overview
Different ML problems require different learning paradigms. At a high level, we categorize ML algorithms by how they learn from data and what kind of feedback they receive.
- Supervised Learning: learn from labeled input–output pairs.
- Unsupervised Learning: discover structure in unlabeled data.
- Semi-Supervised Learning: mix of small labeled and large unlabeled data.
- Reinforcement Learning: learn by interacting with an environment via rewards.
Think of supervised learning as learning with an answer key, unsupervised learning as exploring without a teacher, and reinforcement learning as learning by trial and error with rewards and penalties.
Supervised Learning
In supervised learning, each training example comes with a label. The algorithm learns a mapping from inputs \(X\) to outputs \(y\).
Regression Examples
- Predicting house prices from features (size, location, rooms).
- Forecasting sales given marketing spend.
- Estimating medical costs from patient data.
Classification Examples
- Spam vs non‑spam email detection.
- Fraudulent vs normal transactions.
- Image classification (cat vs dog).
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
model = LogisticRegression()
model.fit(X_train, y_train)
accuracy = model.score(X_test, y_test)
Unsupervised Learning
Unsupervised learning works with unlabeled data. The goal is to discover patterns, structure or groupings in the data.
Clustering
- Customer segmentation in marketing.
- Grouping similar news articles.
- Image compression with K‑Means.
Dimensionality Reduction
- PCA to reduce features before modeling.
- t‑SNE or UMAP for visualization.
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=3, random_state=42)
clusters = kmeans.fit_predict(X)
print(kmeans.cluster_centers_)
Semi-Supervised Learning
Semi‑supervised learning sits between supervised and unsupervised learning. It uses a small amount of labeled data together with a large amount of unlabeled data.
- Labeling data is expensive (medical images, legal documents).
- You have thousands of unlabeled examples, but only a few labels.
Reinforcement Learning
In Reinforcement Learning (RL), an agent interacts with an environment. It takes actions, receives rewards and tries to maximize cumulative reward over time.
- State \(s_t\): current situation.
- Action \(a_t\): choice made by the agent.
- Reward \(r_t\): feedback from the environment.
- Policy \(\pi\): strategy that maps states to actions.
Classic RL applications include game playing (Chess, Go), robotics, recommendation systems and dynamic pricing.