HomeHOME > BLOG > Data Science and BI Analytics > Logistic Regression in Machine Learning: Types, Formula, Working, and Examples
Data Science and BI Analytics

Logistic Regression in Machine Learning: Types, Formula, Working, and Examples

J
UpdatedDecember 2, 2026Read time10 min read
Published on December 2, 2026
SHARE THIS ARTICLE
Jaro Education Facebook PageJaro Education Instagram PageJaro Education Twitter PageJaro Education Whatsapp Page Jaro Education Linkedin PageJaro Education Youtube Page
logistic regression
Table of Contents

Table Of Content

  • Meaning of Logistic Regression
  • Why Logistic Regression Machine Learning Models Still Matter
  • Logistic Regression Formula
  • How Logistic Regression Works

 Every day, software makes thousands of yes-or-no decisions. Is this email spam? Will this customer cancel their subscription? Is this transaction fraudulent? Behind many of these decisions sits a simple but powerful technique called logistic regression. Despite its name, it is not used to predict continuous numbers. It is used to predict categories, and it remains one of the most trusted tools in data science.

In this blog, you will learn the meaning of logistic regression, the formula behind it, how it works step by step, its main types, and real-world examples. The explanations are kept simple so that beginners can follow along, while still being accurate enough for students and working professionals. 

✦Summarize this Article with AI

Meaning of Logistic Regression

The meaning of logistic regression can be explained in one sentence: it is a statistical and machine learning method that estimates the probability that an input belongs to a particular class. The output is always a value between 0 and 1, which makes it easy to interpret as a chance or likelihood. 

For example, suppose a bank wants to know whether a loan applicant will default. A logistic regression model looks at details such as income, age, and credit history, and then returns a probability, such as 0.82. If that probability crosses a chosen threshold, usually 0.5, the applicant is placed in the “will default” class. Otherwise, the applicant is placed in the “will not default” class.  

The word “regression” in the name comes from the fact that the method models a relationship between input variables and an outcome. The word “logistic” refers to the logistic function, also called the sigmoid function, which converts any number into a probability. Even though the output is a class label, the model internally works with probabilities, and that is what makes it so useful.  

 Logistic regression

Also Read:

Why Logistic Regression Machine Learning Models Still Matter

With deep learning and complex ensemble methods getting so much attention, you might wonder why logistic regression machine learning models are still taught and used widely. There are several good reasons. 

First, the method is simple and fast. It trains quickly, even on large datasets, and it needs far less computing power than neural networks. Second, it is easy to interpret. Each input feature has a coefficient that tells you how strongly it pushes the prediction toward one class or the other. This matters in fields such as healthcare, banking, and insurance, where decisions must be explained clearly. Third, it works as a strong baseline. Data scientists often build a logistic regression model first, and then check whether a more complex model truly performs better. 

In supervised learning, logistic regression is one of the first classification algorithms that learners study, because it introduces ideas such as probability, loss functions, and optimization that apply to almost every other model.  

Free Courses
Online MBA Degree ProgrammeOnline MBA Degree Programme
Free Python Course with Certificate – Python for Data Analysis
  • Duration Icon
    Duration : 11 - 15 Hours
  • Aplication Date Icon
    Application Closure Date :
Enquiry Now
Online MBA Degree ProgrammeOnline MBA Degree Programme
Free Generative AI Course with Certificate – Gen AI Tools & Applications
  • Duration Icon
    Duration : 2 – 3 Hours
  • Aplication Date Icon
    Application Closure Date :
Enquiry Now

Logistic Regression Formula

To understand the logistic regression formula, it helps to start with linear regression. A linear model predicts an outcome using this equation: 

z = b0 + b1x1 + b2x2 + … + bnxn

Here, x1 to xn are the input features, b1 to bn are the coefficients (weights), and b0 is the intercept. The problem is that z can be any number, from negative infinity to positive infinity. Probabilities, however, must stay between 0 and 1.

Logistic regression solves this by passing z through the sigmoid function:

P(y = 1) = 1 / (1 + e^(-z))

In this formula, e is Euler’s number, roughly 2.718. When z is a large positive number, the probability gets close to 1. When z is a large negative number, the probability gets close to 0. When z equals 0, the probability is exactly 0.5. This creates the smooth, S-shaped curve that is the signature of logistic regression.   

Odds and Log-Odds

Another way to write the formula uses odds. The odds of an event are the probability that it happens divided by the probability that it does not happen: P / (1 – P). Taking the natural logarithm of the odds gives the log-odds, also called the logit: 

log(P / (1 – P)) = b0 + b1x1 + b2x2 + … + bnxn

This form shows why the method is called a linear model for log-odds. A one-unit increase in a feature x1 changes the log-odds by b1. If you raise e to the power of b1, you get the odds ratio, which many analysts use to explain results in plain language. For instance, an odds ratio of 1.5 means the odds of the outcome rise by 50 percent for each one-unit increase in that feature.

How Logistic Regression Works

Now that you have seen the formula, let us walk through how logistic regression works in practice. The process follows a clear sequence of steps.  

Step 1: Collect and prepare the data. You start with a labeled dataset, where each row has input features and a known outcome, such as 0 or 1. Missing values are handled, categorical variables are converted into numbers, and numeric features are often scaled so that they sit on similar ranges. 

Step 2: Start with initial weights. The model begins with random or zero values for the coefficients.  

Step 3: Calculate predictions. For each row, the model computes z using the current weights and then applies the sigmoid function to get a probability. 

Step 4: Measure the error. Logistic regression uses a loss function called log loss, also known as binary cross-entropy. It penalizes predictions that are confident but wrong much more heavily than predictions that are slightly off. A model that says 0.99 for an event that did not happen receives a very large penalty. 

Step 5: Update the weights. An optimization method, most commonly gradient descent, adjusts the coefficients a little at a time to reduce the loss. Some software uses related methods, such as maximum likelihood estimation with Newton-type solvers, to reach the same goal.   

Step 6: Repeat until it converges. Steps 3 to 5 repeat until the loss stops improving noticeably. At that point, the model has learned the best coefficients it can find from the training data. 

Step 7: Choose a threshold and predict. For new data, the model outputs a probability. A threshold, usually 0.5, turns that probability into a class. You can change the threshold depending on the problem. In medical screening, for example, you might lower it to catch more possible cases. 

The Decision Boundary

The set of points where the predicted probability equals exactly 0.5 is called the decision boundary. In simple logistic regression, this boundary is a straight line (or a flat plane in higher dimensions). Everything on one side is predicted as class 1, and everything on the other side is predicted as class 0. This is why standard logistic regression works best when the classes can be separated reasonably well by a linear boundary.  

Types of Logistic Regression

There are three main types of logistic regression, and each one fits a different kind of outcome.

Types of logistic regression

1. Binary Logistic Regression

This is the most common type. The outcome has only two possible values, such as yes or no, pass or fail, spam or not spam. Everything described so far, including the sigmoid function and the 0.5 threshold, applies directly to the binary case. Examples include predicting whether a customer will buy a product or whether a tumor is benign or malignant.   

2. Multinomial Logistic Regression

When the outcome has three or more categories that have no natural order, multinomial logistic regression is used. It generalizes the binary model with the softmax function, which produces one probability for each class so that all the probabilities add up to 1. Examples include predicting which type of flower a sample belongs to (setosa, versicolor, or virginica) or which genre a movie falls into.   

3. Ordinal Logistic Regression

Ordinal logistic regression is used when the outcome has three or more categories that follow a meaningful order. Think of customer ratings such as poor, average, good, and excellent, or education levels such as high school, bachelor’s, and master’s. The model respects the ranking of these categories, which gives it more power than treating them as unrelated groups.   

Logistic Regression Analysis: How to Evaluate Your Model

Building a model is only half the job. A careful logistic regression analysis also checks how well the model performs and whether its results can be trusted. Here are the most common tools. 

Confusion matrix. This table compares predicted classes with actual classes. It shows the number of true positives, true negatives, false positives, and false negatives, which are the building blocks of most other metrics.

Accuracy. This is the share of all predictions that were correct. It is easy to understand, but it can be misleading when one class is much larger than the other. A model that always predicts “no fraud” can be 99 percent accurate if only 1 percent of transactions are fraudulent, yet it is useless. 

Precision and recall. Precision tells you how many of the predicted positives were truly positive. Recall tells you how many of the actual positives the model managed to find. The F1 score combines the two into a single number. 

ROC curve and AUC. The ROC curve plots the true positive rate against the false positive rate at different thresholds. The area under this curve, called AUC, summarizes how well the model separates the two classes. A value of 0.5 means random guessing, while 1.0 means perfect separation. 

Coefficients and p-values. In statistical settings, analysts look at each coefficient, its standard error, and its p-value to judge whether a feature has a meaningful relationship with the outcome. Odds ratios make these coefficients easier to explain to non-technical readers.  

It is also important to check the main assumptions: the outcome should be binary (or categorical for the other types), the observations should be independent, the input features should not be highly correlated with each other, and there should be a linear relationship between the features and the log-odds. 

Examples of Logistic Regression in Real Life

Seeing logistic regression machine learning in action makes the idea much clearer. Here are some practical examples.

Email spam detection. The model reads features such as the number of links, certain keywords, and sender reputation, and then estimates the probability that a message is spam.

Medical diagnosis. Doctors and researchers use logistic regression to estimate the chance that a patient has a disease based on age, blood pressure, cholesterol, and other test results. The interpretable coefficients help clinicians understand which factors matter most.

Credit scoring and fraud detection. Banks use the model to predict loan default and to flag suspicious card transactions in real time.

Customer churn prediction. Telecom and subscription companies predict which customers are likely to leave, so they can offer timely discounts or support. 

Marketing and conversion. Marketers estimate whether a website visitor will click an ad or complete a purchase, using details like browsing time and past behavior.     

A Simple Worked Example

Imagine a model that predicts whether a student passes an exam based on hours studied. After training, suppose the model finds b0 = -4 and b1 = 1.0. For a student who studies 5 hours, z = -4 + (1.0 × 5) = 1. The probability of passing is 1 / (1 + e^(-1)), which is about 0.73. Since 0.73 is above 0.5, the model predicts that the student will pass. A student who studies only 2 hours gets z = -2, which gives a probability of about 0.12, so the model predicts a fail. 

Here is a short Python snippet showing how this is done with scikit-learn: 

from sklearn.linear_model import LogisticRegression

from sklearn.model_selection import train_test_split

from sklearn.metrics import accuracy_score

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

model = LogisticRegression()

model.fit(X_train, y_train)

predictions = model.predict(X_test)

print(“Accuracy:”, accuracy_score(y_test, predictions))

Advantages and Limitations of Logistic Regression

  • It is simple to implement and quick to train.
  • It gives probabilities, not just class labels.
  • Results are easy to interpret and explain.
  • It performs well when the classes are roughly linearly separable.
  • With regularization (L1 or L2), it can handle many features and reduce overfitting.  

Limitations

  • It assumes a linear relationship between features and log-odds, so it can struggle with complex patterns.
  • It is sensitive to outliers and highly correlated features.
  • It may underperform on very large, unstructured data such as images or raw text, where deep learning is stronger.
  • It needs a reasonably large sample size to give stable results.   
Also Read:

Conclusion

Logistic regression is a classic example of a simple idea that works remarkably well. By combining a linear equation with the sigmoid function, it turns raw input data into clear probabilities and reliable class predictions. Whether you are classifying emails, predicting customer behavior, or supporting medical decisions, the method offers speed, transparency, and solid performance.

If you are starting your machine learning journey, learning logistic regression is a smart first step. It teaches you the core ideas of probability, loss, and optimization, and it gives you a dependable baseline against which every other model can be measured.

Frequently Asked Questions

Logistic regression is a method that predicts the probability of an outcome falling into a specific category, such as yes or no. It uses the sigmoid function to turn a weighted sum of inputs into a number between 0 and 1.

Despite its name, logistic regression is a classification algorithm. It is called regression because it models the relationship between inputs and the log-odds of an outcome, but its final purpose is to assign data to classes.

Linear regression predicts a continuous value, such as house price or temperature, and its output can be any number. Logistic regression predicts a probability between 0 and 1 and is used for categorical outcomes. They also use different loss functions: mean squared error for linear regression and log loss for logistic regression.

Yes. Logistic regression is widely used in finance, healthcare, marketing, and research because it is fast, interpretable, and dependable. It is also a standard baseline model, and in many tabular-data problems it performs very close to far more complex models. Many teams also prefer it where regulations demand clear explanations of every prediction. 
Bhargavi R

Bhargavi R

HR Professional
Bhargavi Reddy is an HR professional with over 6 years of experience in IT recruitment and talent acquisition. She specializes in hiring across technologies like Java, DevOps, Python, and Data Engineering. With strong expertise in full-cycle recruitment and stakeholder management, she focuses on building high-performing teams. Currently, she works as an HR Manager driving strategic hiring initiatives.

Get Free Upskilling Guidance

Fill in the details for a free consultation

*By clicking "Submit Inquiry", you authorize Jaro Education to call/email/SMS/WhatsApp you for your query.

Find a Program made just for YOU

We'll help you find the right fit for your solution. Let's get you connected with the perfect solution.

Confused which course is best for you?

Is Your Upskilling Effort worth it?

LeftAnchor ROI CalculatorRightAnchor
Confused which course is best for you?
Are Your Skills Meeting Job Demands?
LeftAnchor Try our Skill Gap toolRightAnchor
Confused which course is best for you?
Experience Lifelong Learning and Connect with Like-minded Professionals
LeftAnchor Explore Jaro ConnectRightAnchor
EllispeLeftEllispeRight