Chapter 17 of 42 · ~16 min read & lab+60 XP
Chapter 17 · Machine Learning

Binary vs. Multiclass vs. Multi-Label Classification: OvR, OvO & Softmax

How to pick the right output head, loss function, and strategy when classifying 2 classes, K mutually exclusive classes, or multiple simultaneous tags

What Is It?

Classification comes in three distinct flavors: Binary (1 yes/no decision), Multiclass (pick exactly 1 winner out of K mutually exclusive classes), and Multi-Label (predict multiple independent yes/no tags for the same item).

Why Is It Required?

Using Softmax on a Multi-Label problem forces tags to compete and sum to 1 (preventing a movie from being BOTH Action and Comedy!), while confusing OvR with OvO wastes compute.

Everyday Analogy: Binary = light switch (on/off); Multiclass = radio buttons (pick exactly one country); Multi-Label = checkboxes (select all movie genres that apply).
Why ML Engineers & Data Scientists Actually Need This

Choosing Softmax vs. Independent Sigmoids is one of the most common real-world architecture bugs in NLP tagging, medical coding, and computer vision.

ML / AI Engineer

Using BCEWithLogitsLoss (independent sigmoids) instead of CrossEntropyLoss (softmax) is mandatory for multi-label tagging systems.

Data Scientist

Knowing Macro-F1 vs. Micro-F1 prevents rare classes from being hidden by a dominant majority class.

Interview & Debug Edge

Classic question: 'A photo can contain a dog, a car, and a tree all at once. Why does Softmax fail here, and what should you use instead?'

Step 0 · Test Your Gut Before Any Math!

You have K = 10 mutually exclusive classes (handwritten digits 0–9) and want to extend a binary SVM using One-vs-One (OvO). How many binary SVMs are trained?

What You Will Master in This Chapter
  • Distinguish Binary, Multiclass, and Multi-Label classification on sight.
  • Choose the right activation & loss for each: Sigmoid + BCE (Binary), Softmax + Categorical CE (Multiclass), Independent Sigmoids + BCE (Multi-Label).
  • Compare One-vs-Rest (OvR: K classifiers) vs. One-vs-One (OvO: K(K−1)/2 classifiers) for extending binary models like SVM.
  • Pick Macro vs. Micro vs. Weighted F1 for multi-class evaluation.
Plain-English Symbol Decoder · Click Any Symbol Before We Begin
1 / 2
Softmax(z)k=ezk∑j=1Kezj\text{Softmax}(z)_k = \frac{e^{z_k}}{\sum_{j=1}^K e^{z_j}}Say aloud:“Softmax probability vector”
Plain-English Meaning
Forces all K class probabilities to be positive and sum to exactly 1.0 (mutually exclusive).
Everyday Example
Digit classifier: [0.01, 0.02, 0.94, ...] summing to 1.0.
Story-First Intuition, Visual Diagrams & Interactive Walkthroughs

Ask one simple question: Can two labels be true at the exact same time? If No (a digit cannot be both 3 and 8) → Multiclass with Softmax. If Yes (an article can be both Tech and Finance) → Multi-Label with K independent Sigmoids!

1. The 3 Classification Setups Side by Side

TypeLabels per RowOutput ActivationLoss FunctionExample
Binary1 of 2 ({0,1}\{0,1\})1 SigmoidBinary Cross-EntropyFraud / Spam
MulticlassExactly 1 of KKSoftmax (∑pk=1\sum p_k = 1)Categorical Cross-EntropyDigit 0–9, Language ID
Multi-Label0, 1, or many of KKKK Independent SigmoidsSum of Binary Cross-EntropiesMovie genres, Medical ICD tags
Hands-On Mini-Lab · Softmax Temperature Dial (Used in Classifiers & Every LLM!)
Cat (z=2.4)70.8%
Dog (z=1.2)21.3%
Fox (z=0.2)7.8%

2. One-vs-Rest (OvR) vs. One-vs-One (OvO)

When using a strictly binary algorithm (like classic SVM) on KK classes:

  • One-vs-Rest (OvR): Train KK classifiers (Class kk vs. all other K−1K-1 classes). Fast (O(K)O(K) models), but each sub-problem is imbalanced.
  • One-vs-One (OvO): Train K(K−1)2\frac{K(K-1)}{2} classifiers (every pair of classes). Each model sees a tiny balanced slice, great for slow O(N2)O(N^2) Kernel SVMs when KK is modest.
“Wait, I'm Confused...” · Teacher Office Hours Q&A

The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.

Macro-F1 averages the F1 score of every class equally (so a rare 1% class counts just as much as a 90% class). Micro-F1 pools all predictions together (in single-label multiclass, Micro-F1 equals plain Accuracy!).

Interactive Visual Lab
Lab Challenge: Explore how linear decision boundaries carve feature space into class probabilities.
Interactive Stage • Logistic Regression & Binary Cross-Entropy

Tune Steepness w & Boundary Shift x₀ to Minimize Log-Loss

Log-Loss = 0.134
Intuition Takeaway: Radio buttons (mutually exclusive) → Softmax + Categorical Cross-Entropy; Checkboxes (multiple simultaneous tags) → Independent Sigmoids + Binary Cross-Entropy.
Production NumPy & PyTorch Code Patterns
import numpy as np

# Multiclass Softmax (sums to 1) vs. Multi-Label Independent Sigmoids (can all be high!)
logits = np.array([2.4, 2.1, -1.8])  # raw scores for [Action, Comedy, Horror]

# 1. Multiclass Softmax (forces mutually exclusive competition)
shifted = logits - logits.max()
softmax_probs = np.exp(shifted) / np.exp(shifted).sum()

# 2. Multi-Label Independent Sigmoids (each genre judged independently)
sigmoid_probs = 1.0 / (1.0 + np.exp(-logits))

print("Softmax (Multiclass, sum=1):    ", np.round(softmax_probs, 3).tolist())
print("Sigmoids (Multi-Label, indep.): ", np.round(sigmoid_probs, 3).tolist())
print("Predicted Multi-Label tags (>0.5):", [g for g, p in zip(["Action", "Comedy", "Horror"], sigmoid_probs) if p > 0.5])
Common ML Interview Traps & Numerical Pitfalls
Trap #1: Using Softmax + Cross-Entropy for a multi-label tagging task.
Best Practice: Softmax forces probabilities to sum to 1, punishing co-occurring labels. Use K independent Sigmoids + Binary Cross-Entropy!
Chapter Mastery Check (+60 XP)
Score: 0 / 1
1A chest X-ray can simultaneously show pneumonia, cardiomegaly, and pleural effusion. Which output layer and loss should you use?

Apply What You Learned — Solve Matching Coding Problems