Learning Library

← Back to Library

Logistic Regression for Binary Classification

Key Points

  • Logistic regression extends linear regression to handle categorical (non‑numeric) data by modeling the probability that an instance belongs to one of two classes.
  • It is well suited for binary classification tasks, where each observation must be assigned to one of two categories (e.g., “cat” vs. “not a cat”).
  • The algorithm uses binary input features encoded as 0/1 (such as presence of four legs, whiskers, or claws) and learns a weighted linear combination of these features.
  • A sigmoid (logistic) function maps the linear combination to a value between 0 and 1, representing the predicted probability of belonging to the positive class.
  • A decision threshold (commonly 0.5) converts the probability into a concrete class label: probabilities ≥ 0.5 are classified as “cat,” while lower values are classified as “not a cat.”

Full Transcript

# Logistic Regression for Binary Classification **Source:** [https://www.youtube.com/watch?v=AX-ZEC-71DI](https://www.youtube.com/watch?v=AX-ZEC-71DI) **Duration:** 00:05:09 ## Summary - Logistic regression extends linear regression to handle categorical (non‑numeric) data by modeling the probability that an instance belongs to one of two classes. - It is well suited for binary classification tasks, where each observation must be assigned to one of two categories (e.g., “cat” vs. “not a cat”). - The algorithm uses binary input features encoded as 0/1 (such as presence of four legs, whiskers, or claws) and learns a weighted linear combination of these features. - A sigmoid (logistic) function maps the linear combination to a value between 0 and 1, representing the predicted probability of belonging to the positive class. - A decision threshold (commonly 0.5) converts the probability into a concrete class label: probabilities ≥ 0.5 are classified as “cat,” while lower values are classified as “not a cat.” ## Sections - [00:00:00](https://www.youtube.com/watch?v=AX-ZEC-71DI&t=0s) **Logistic Regression for Binary Classification** - The excerpt explains how logistic regression handles categorical, binary data by using a cat‑vs‑non‑cat example where features like legs, whiskers, and claws are encoded as 0s and 1s to predict the probability of each animal belonging to the “cat” class. ## Full Transcript
0:00often we can use linear regression to 0:03generate predictions for numerical 0:05continuous data such as height weight or 0:08temperature but what if you have data 0:10that cannot be expressed in numbers such 0:12as color gender or job roll in this 0:16video we'll give a brief overview on how 0:18to use logistic regression as a machine 0:20learning technique for categorical data 0:23categorical data consists of discrete 0:25values that describe an object for 0:27example the species of an animal 0:30logistic regression is a great candidate 0:32for machine learning problems that 0:34involve binary classification which 0:36determines the probability that each 0:38data entry can be classified into one of 0:40two different 0:42categories here's an example let's say 0:45that we have a data set that contains 0:46information about different animals and 0:48we are tasked with identifying each 0:51animal as either a cat or not a 0:55cat here's our data set and let's say 0:58that it's filled with some distinct 1:00ising features for each animal let's say 1:02that we have three features we have 1:05whether or not the animal has four legs 1:09whether or not the animal has 1:12whiskers or whether or not the animal 1:15has 1:17claws and finally since this is a 1:19supervised learning approach we are 1:20going to tell the machine learning 1:22algorithm whether or not each data entry 1:25is a cat or not because these are all 1:28binary features that that can either be 1:30yes or no we're going to fill them in 1:32with zeros and ones zero means false and 1:36one is 1:38true let's say for the first animal the 1:42first animal does not have four legs it 1:45does not have whiskers it does not have 1:47claws and it is not a cat the second 1:51animal does have four legs but it does 1:54not have whiskers it does not have claws 1:57and it is not a cat and the third animal 2:00does have four legs it does have 2:03whiskers it does have claws and it is a 2:07cat so now we have to determine if this 2:11machine learning algorithm is able to 2:13figure out whether or not each animal is 2:17a cat or not a cat based on the 2:19probabilities that are generated by 2:21logistic regression logistic regression 2:24uses the sigmoid function also known as 2:27the logistic function to map a linear 2:29combination of the input features into a 2:32range of 0 to 1 so this is what the 2:35sigmoid function looks 2:41like so the function as you may have 2:44seen before is f ofx = 1/ 1 + a 2:49mathematical constant to 2:53thex this is a graph of what the sigmoid 2:56function typically looks like as you can 2:59see here here it's an s-shaped curve 3:01where all of the Y values are in between 3:030 and 1 as the model evaluates each data 3:07entry the outputs will be a number 3:09between zero and one which represent the 3:12probability that each data entry is in 3:15the first category which is the cat 3:18category or the one category we use the 3:21decision boundary to determine at which 3:23point we will assign each data entry to 3:26each 3:27category if the decision bound 3:31is 3:350.5 that means that for any 3:38probabilities of 0.5 or 3:44greater it will be in the C 3:47category or 3:50one but for any decision boundary that 3:53is less than 3:550.5 it will be in the not C category 3:59or 4:01zero thus the closer the predicted value 4:04is to one the more likely it is to be in 4:07the cat category or in other terms that 4:11is How likely it is predicted to be a 4:14cat if you look at our data again you 4:17can see that in the cat or not cat 4:19category we will have either a zero or 4:21one this is where the logistic 4:24regression model will make the 4:25predictions so each line or each data 4:29entry in this chart will be given a zero 4:32for not a cat or one for a cat ideally 4:36we would want to get the same results 4:38that we put into the model so we would 4:41say that the first one is not a cat the 4:44second one is not a cat but the third 4:46one is a cat so ideally we should get 4:49z0 and one overall logistic regression 4:53is a great place to start if you're 4:54looking for a supervised machine 4:56learning technique for binary 4:58classification 4:59if you like this video please like And 5:02subscribe if you have any questions or 5:04want to share your thoughts about this 5:05topic please leave a comment below