Skip to content
E
Educatum

Supervised vs. Unsupervised Learning

Curated by Educatum AI teamLast updated:
Basic Concepts
Direct Answer

Supervised learning trains models on labeled input-output pairs to predict targets or classify new observations. Unsupervised learning operates on unlabeled inputs without explicit target labels to uncover latent patterns, clusters, low-dimensional manifolds, or anomalies within the data itself.

Study Card: Supervised vs. Unsupervised Learning

Direct Answer

  • Supervised Learning learns a mapping f(x)≈yf(x) \approx y from labeled input-output pairs (xi,yi)(x_i, y_i) to predict continuous targets (regression) or discrete categories (classification) on unseen data. Practical applications include spam detection, medical image diagnosis, click-through prediction, and demand forecasting.
  • Unsupervised Learning analyzes unlabeled inputs {xi}\{x_i\} without ground-truth targets to uncover hidden structure—including clustering (grouping similar items), dimensionality reduction (compressing correlated features), and density estimation / anomaly detection. Practical applications include customer segmentation, exploratory data visualization, and fraud/outlier screening.

Key Terms

  • Supervised Learning: Learning predictive input-to-label mappings from annotated examples evaluated via direct target metrics (MSE, log loss, F1, accuracy).
  • Unsupervised Learning: Discovering structure from inputs alone, often evaluated via reconstruction error, log-likelihood, cluster validity indices, or downstream utility.
  • Labeled Data: Observations paired with human-annotated or logged ground-truth targets yy.
  • Unlabeled Data: Observations containing only input feature vectors xx.
  • Features: Measurable input attributes fed into a learning algorithm.

Example

Consider an e-commerce customer dataset containing purchase history, tenure, and site activity:

  • Supervised Learning (Churn Prediction): Historical customers carry known churn labels (yes / no). A classifier trains on those labeled records to predict the probability that an active customer will churn next month.
  • Unsupervised Learning (Customer Segmentation): Using the same feature table without churn labels, K-means or GMM groups customers into natural behavioral segments (e.g., high-frequency loyal buyers vs. seasonal bargain hunters) for marketing strategy or exploratory analysis.

Code Implementation

import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.cluster import KMeans
from sklearn.datasets import make_regression, make_blobs

# 1. Supervised Learning Example (Linear Regression with labeled targets y_reg)
X_reg, y_reg = make_regression(n_samples=100, n_features=1, noise=10, random_state=42)
X_train_reg, X_test_reg, y_train_reg, y_test_reg = train_test_split(
    X_reg, y_reg, test_size=0.2, random_state=42
)

model_reg = LinearRegression()
model_reg.fit(X_train_reg, y_train_reg)
y_pred_reg = model_reg.predict(X_test_reg)

plt.figure(figsize=(12, 5))
plt.subplot(1, 2, 1)
plt.scatter(X_train_reg, y_train_reg, label="Training Data")
plt.plot(X_test_reg, y_pred_reg, color='red', label="Predicted Line")
plt.title("Supervised Learning (Linear Regression)")
plt.legend()

# 2. Unsupervised Learning Example (KMeans Clustering on unlabeled X_cluster)
X_cluster, _ = make_blobs(n_samples=150, centers=3, n_features=2, random_state=42)

kmeans = KMeans(n_clusters=3, random_state=42)
y_kmeans = kmeans.fit_predict(X_cluster)
centers = kmeans.cluster_centers_

plt.subplot(1, 2, 2)
plt.scatter(X_cluster[:, 0], X_cluster[:, 1], c=y_kmeans, s=50, cmap='viridis', label='Clustered Points')
plt.scatter(centers[:, 0], centers[:, 1], c='black', s=200, alpha=0.6, marker='X', label='Centroids')
plt.title("Unsupervised Learning (KMeans Clustering)")
plt.legend()
plt.tight_layout()
plt.show()
  • Self-Supervised Learning: Bridges unlabeled data and supervised training by automatically constructing pretext supervision from raw data itself (e.g., next-token prediction in LLMs, masked image/token modeling, or contrastive learning).
  • Semi-Supervised Learning: Combines a small labeled set with a large unlabeled corpus (e.g., via pseudo-labeling or consistency regularization) when labeling is costly.
  • Reinforcement Learning: An agent learns sequential decision policies via trial-and-error interaction with an environment to maximize cumulative expected reward rather than learning from static labeled datasets.
  • Clustering Algorithms: K-means, Gaussian Mixture Models (GMM), hierarchical clustering, and DBSCAN / HDBSCAN.
  • Dimensionality Reduction: Linear projection (PCA) and non-linear manifold embeddings (t-SNE, UMAP, autoencoders).
View all →

Try keywords like RoPE, FlashAttention, DPO, or Blind 75.