Welcome to “Learn with Eskwelabs!” This series is called “From the Notebook of Our Fellows” because you will be guided by our very own alumni through a mix of basic and advanced data science concepts. Every time you read from one of our Fellows’ notebooks, just imagine that you have a data BFF or lifelong learning friend who’ll hold your hand at every step.
Hi, everyone! My name is Basty, and I’m a data scientist and educator from Metro Manila. If there’s something I value so much, that is education. Education has allowed me to not only dive into the amazing world of code and data, but also to encourage and inspire others to do the same. Read more about me here.
Outside of work and school, I love playing video games like Valorant and League of Legends. I also love listening to Broadway musicals (HAMILTON, DEH, TICK TICK BOOM ALL THE WAY!). Lastly, I LOVE watching Friends, New Girl, HIMYM, and The Big Bang Theory.
Now, let’s take a look at my notebook!
In this article, we’ll be learning about another famous and simple machine learning algorithm: Logistic Regression! There are a lot of articles out there for this algorithm, but most of them are purely mathematical, and this blog post isn’t so. Alright, LET’S GOOO!
In my previous post, we learned about Linear Regression. Now at this point you might already have questions regarding the difference between Linear Regression and Logistic Regression because they both have the word “regression.” Are they the same thing? Are they both used for predicting something? Or perhaps they’re brothers…...I’m sure you have a lot more questions, so let’s get started!
Before we even go about learning the algorithm itself, let’s first recall what we learned in my two previous articles.
Now even though the algorithm we’ll be learning about has the word “regression” in it, it doesn’t mean it’s also the same thing as Linear Regression. Actually, Logistic Regression is an algorithm that we used for classification problems.
In machine learning, classification is a supervised learning concept which basically categorizes the data into classes.
To understand this better, let’s compare it to clustering. In clustering, our primary goal is to group the data into clusters based on their similarities. But in classification, our primary goal is to assign a label or class to the data, and then predict what class the given data points belong to. For example, you want to classify if an email is spam or not, or maybe you want to classify a certain movie’s genre.
Think of regression, clustering, and classification as Thor, Captain America, and Iron Man of the Avengers. They are the main machine learning tasks you’ll be encountering in your career as a data scientist!
Now that we have an understanding of what classification is in machine learning, let’s actually try to understand what our main topic is really about. As I’ve mentioned earlier, Logistic Regression is something we used for classification problems, and so we can still apply the same concept to it.
Logistic regression is a supervised learning algorithm used to predict a dependent categorical target variable. In other words, we use this algorithm to predict what category our dependent variable belongs to.
Although, always keep in mind that the dependent variable we are trying to classify should be categorical, meaning it’s labeled, unlike numerical values which aren’t labeled.
I try to always apply a concept into an example to understand it better, and to actually visualize how it works, and so here’s an example of Logistic Regression. Imagine you were given a dog and an orange and you wanted to find out whether each of these items was an animal or not. The result of this task would be for the dog to end up classified as an animal, and for the orange to be categorized as not an animal. So in this example, we are trying to predict whether the two objects are animals or not.
“Okay, now I know the primary goal of Logistic Regression is to classify whether something belongs to a certain class or not, but how does it actually determine if something belongs to that certain class?” Excellent question! Let’s dive a little deeper into how the algorithm would classify our given example. Just like in Linear Regression, we have independent variables that we choose to predict the dependent variable, and that applies here as well.
The model would have to know some characteristics of the items first before deciding where they belong. Since our example includes a dog and an orange, the characteristics could be the color, size, weight, shape, height, or even number of legs. In this way, knowing that an orange’s shape was a circle may help the algorithm to conclude that the orange was not an animal. Similarly, knowing that the orange had zero limbs would help as well.
“Basty, the example that you gave only used two labels: animal or not animal, but how about if I want to classify if it’s a dog, cat, or fish?” Your questions keep getting better and better, my friend!
There are three main types of Logistic Regression that you’ll be encountering: binary, multinomial, and ordinal. They all differ in terms of theory and execution. Let’s go through them one by one!
You already got introduced to this type of Logistic Regression earlier with the classifying of a dog and orange as an animal or not. In this type of logistic regression, there are only two possible outcomes. This type is typically represented as a 1 or 0.
Here’s an example of a Binary Logistic Regression:
This type of Logistic Regression requires multiple classes that an item can be classified as. In order to do this, you need to have at least three or more classes to run this algorithm.
Here’s an example of a Multinomial Logistic Regression:
This type of Logistic Regression is still the same with a Multinomial Logistic Regression, but this requires order with the classes being defined.
Here’s an example of an Ordinal Logistic Regression:
We now have discussed the different types of logistic regression, and at this point, you might be wondering what the difference is between a Linear Regression model and Logistic Regression model.
There are still a couple of differences between a Linear Regression model and Logistic Regression model that can be helpful for you to know about, and most of it already tackles the mathematical aspect of it. Here is an additional resource for you to check out!
We already brought up a lot of examples where Logistic Regression is used, but where is it actually used in the real-world? Let’s go through them, shall we?
I know that up to this point, we haven’t been technical in terms of discussing Logistic Regression, but now we need to get our hands dirty with some code! Just like in our previous articles, we’d be using scikit-learn! Scikit-learn is a free Python library that contains tools for machine learning projects.
In the article, we tackled Logistic Regression in a non-technical and mathematical way to have an understanding of it. However, having a basic understanding of what it is is not enough. We still need to know how it technically works as an algorithm. Here is an additional resource that I think can help you have a better grasp of the algorithm in terms of its technicalities.
So just to recap what we learned today:
To summarize: Logistic regression is a statistical analysis method to predict a binary outcome, such as yes or no, based on prior observations of a data set..
There is still a lot to learn about how Logistic Regression works as an algorithm, and this article was mainly to give you a boost towards it. Aside from the resources that I gave you, one of the many ways you can also learn the how’s of Logistic Regression is through the 12-week Data Science Fellowship, wherein you’ll be doing multiple projects using different technologies across different industries!.
Maybe you’re interested in predicting what specific genres your favorite spotify playlist songs fall under? Or if you’re interested in the banking industry, predicting whether a customer is likely to churn or not is something that gets your interest. Discover all those answers and harness the power of classification through the bootcamp!.
Hopefully this article was able to help you gain a basic understanding to boost your learning of how Logistic Regression works and made machine learning a little less intimidating.
Updated for Data Science Fellowship Cohort 10 | Classes for Cohort 10 start on September 12, 2022.
If you’re ready to dive in
If you want to know more
Bootcamp payment options
Other Bootcamp features