Multi-Class Logistic Regression in SciKit Learn
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction to Multi-Class Logistic Regression
Logistic regression is a popular statistical method used for binary classification problems, which predicts the probability of one binary outcome. However, many real-world problems involve multi-class classification, that is, more than two classes or outcomes. Multi-class logistic regression is an extension that enables such predictions.
In this article, we will delve into the workings of multi-class logistic regression using the Python library SciKit Learn, a leading machine learning toolkit.
Logistic Regression
Before diving into multi-class logistic regression, it's important to first understand the basic logistic regression model. Logistic regression is used to model the probability of a certain class or event. It is a linear classifier that uses a logistic function to output probabilities between 0 and 1:
Where: • are the parameters to be estimated. • are the independent variables.
Multi-Class Logistic Regression
One-vs-Rest (OvR) Strategy
The most common approach for extending logistic regression to multi-class problems is the One-vs-Rest (OvR) strategy. Here, a binary classifier is built for each class, distinguishing that class from all other classes. The class with the highest probability is chosen as the predicted class.
Softmax Function
Another approach is the Softmax function, commonly used in conjunction with neural networks but applicable to logistic regression too. It generalizes the logistic function for multiple classes:
Where: • is class . • is the total number of classes.
Implementing Multi-Class Logistic Regression in SciKit Learn
SciKit Learn provides a straightforward API to implement multi-class logistic regression using the `LogisticRegression` class.
Example
Related reading
- Multi-Class SVM. Binary Decision Tree. Issues with LIBSVM
- Multi-Class SVM one versus all
- Multi-label classification Keras metrics
- multi-layer perceptron MLP architecture criteria for choosing number of hidden layers and size of the hidden layer?
- Multi-threaded use of SQLAlchemy
- multilabel binarizer float object not iterable
- Multi-output neural network combining regression and classification
- Multi-output regression
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.