← Learn AI
C_000228 · machine learning · advanced

Logistic Regression

Modelling the log-odds of a binary outcome as a linear function of predictors, giving calibrated probabilities.

Step 1 of 4

In words

What it is, why it matters, and what it is like.

Why am I learning this?

Imagine you are designing a system to decide whether to approve a loan application. A simple 'yes' or 'no' answer is often not enough. You might need to know the *chance* of default to weigh it against other factors, or to report risk levels to regulators. Logistic regression is the standard tool for turning raw data—like income, credit history, and employment length—into a clear probability between 0% and 100%. It is the foundational building block for more complex AI systems, but its immediate value is giving you a quantifiable measure of confidence rather than just a binary guess. If you want to build systems that predict categories, such as detecting fraud, diagnosing disease, or predicting customer churn, this technique is your starting point.

The idea, in plain terms

Suppose you want to predict whether a specific email is spam (yes/no) based on two pieces of information: the number of exclamation marks in the subject line and whether the word 'winner' appears in the body. Let's say there are 3 exclamation marks and the word 'winner' is present. Logistic regression works by assigning a 'weight' to each piece of evidence that reflects how strongly it predicts spam. For example, let's assume the weight for 'winner' is very high (say, 5.0) because its presence is a strong indicator, while the weight for exclamation marks is lower (say, 0.5). It also has a 'baseline' setting (called bias) that starts the score at a neutral point, say -2.0.

First, it multiplies each input by its weight: the 'winner' feature contributes 1 * 5.0 = 5.0 points, and the exclamation marks contribute 3 * 0.5 = 1.5 points. Then, it adds these products together along with the baseline: -2.0 + 5.0 + 1.5 = 4.5. This total, 4.5, is a raw score that can be any number from negative infinity to positive infinity. However, probabilities must be between 0 and 1. So, this score is passed through a special 'squashing' curve (the logistic function). This curve squeezes the infinite range of scores down into the 0-to-1 range. A high positive score like 4.5 gets squashed to a probability very close to 1.0 (99% chance of spam), while a low negative score would be squashed to near 0.0. The model 'learns' by looking at thousands of past emails, adjusting the weights and bias until its squashed probabilities match the actual labels (spam/not spam) as closely as possible.

An analogy

Think of a judge deciding if a defendant should be released on bail. The judge looks at several risk factors: prior criminal record, current employment status, and residence stability. Each factor has a certain 'danger level' associated with it based on the judge's experience—the prior record might add significant risk points, while stable housing subtracts them. The judge mentally sums these weighted concerns to get a total risk score. However, instead of issuing a raw number like '73', the judge translates that sum into a practical judgment: 'the risk is about 85%'. This translation from a raw sum of concerns to a final probability is the core mechanism of logistic regression. The judge also has a personal baseline tendency to be either lenient or strict, which acts as the bias term. Just like the judge refines their judgment by reviewing past case outcomes, the model adjusts its weights through training on historical data. Caveat: This analogy simplifies reality; judges often consider complex interactions between factors that a simple linear sum might miss, whereas logistic regression strictly treats features as additive contributions to the risk score.

Definition

Logistic regression predicts the probability of a binary outcome by computing a weighted sum of input features, adding a baseline value, and then passing that total through a sigmoid function to squash it into a range between 0 and 1.

Where this sits

This technique sits directly alongside Linear Regression, which you have likely encountered or will encounter soon; while linear regression predicts a continuous number by fitting a straight line through data points, logistic regression takes that same linear approach but applies a squashing curve to predict a probability instead. It is also the simplest form of a classifier, which is any model designed to assign data to a specific category, serving as the fundamental baseline against which more complex categorization methods are compared.

Signal from the Frontier

Get the next essay on mind, machine, and meaning

Essays at the intersection of AI, philosophy, and Indian governance. No promotional content.

We'll send a one-click sign-in link to confirm. No password needed.

Views expressed are personal and do not represent the Government of India or the Government of Uttarakhand.