Multiclass Classification with Neural Networks
Learn how to extend binary classification to multiclass classification using neural networks, where the output layer consists of multiple units representing different classes, and the final prediction is made by selecting the class with the highest output value.
Multiclass Classification with Neural Networks
Extending Binary Classification
In binary classification, our hypothesis outputs a single value:
For multiclass classification, instead of returning a single value,
our hypothesis returns a vector of probabilities.
Example: Four-Class Classification
Suppose we want to classify an image into one of four categories:
- Car
- Pedestrian
- Truck
- Motorcycle
Instead of one output unit, we use four output units.
Network Structure
Each output unit corresponds to one class.
Output Representation
Our hypothesis now returns:
Where:
- → Probability of Car
- → Probability of Pedestrian
- → Probability of Truck
- → Probability of Motorcycle
Training Labels (One-Hot Encoding)
Each training example has a label vector:
Examples:
Car:
Motorcycle:
This is called one-hot encoding.
Example Output
Suppose the network outputs:
This means:
So the predicted class is the third category.
If we defined:
1 → Car
2 → Pedestrian
3 → Truck
4 → Motorcycle
Then the model predicts:
Decision Rule
In practice, we select:
That is, we choose the class with the largest output value.
Key Idea
- Binary classification → 1 output unit
- Multiclass classification → K output units
- Output layer size = number of classes
- Final prediction = index of largest output
Neural networks naturally extend logistic regression to multiple classes by simply increasing the number of output neurons.
