Logistic regression is a very popular machine learning technique. We use logistic regression when the dependent variable is categorical. This article will focus on the implementation of logistic regression for multiclass classification problems. I am assuming that you already know how to implement a binary classification with Logistic Regression.

If you haven’t worked on binary classification with logistic regression yet, I suggest, please go through this article before you dive into this one.

Because multiclass classification is built on the binary classification

The implementation of Multiclass classification follows the same ideas as the binary classification. As you know in binary classification, we solve a yes or no problem. Like in the example in the above-mentioned article, the output answered the question if a person has heart disease or not. We had only two classes: heart disease and no heart disease.

If the output is 1, the person has heart disease, and if the output is 0 the person does not have heart disease.

In multi-class classification, we have more than two classes. Here is an example. Say, we have different features and characteristics of cars, trucks, bikes, and boats as input features. Our job is to predict the label(car, truck, bike, or boat).

How to solve this?

We will treat each class as a binary classification problem the way we solved a heart disease or no heart disease problem.

This approach is called the one vs all method

In the one vs all method, when we work with a class, that class is denoted by 1 and the rest of the classes becomes 0.

For example, if we have four classes: cars, trucks, bikes, and boats. When we will work on the car, we will use the car as 1 and the rest of the classes as zeros. Again, when we will work on the truck, the element of the truck will be one, and the rest of the classes will be zeros.

It will be more understandable when you will implement it. I suggest, you keep coding and running the codes as you read.

#towards-data-science #python #machine-learning #logistic-regression #data-science

22.65 GEEK