Logistic Regression Explained: How Machines Sort Yes from No

Logistic regression explained in plain terms means understanding the model that answers yes-or-no questions with a probability, instead of a straight guess. The central question is how a computer can look at a set of numbers and decide whether an email is spam, a loan will be repaid, or a patient is at risk, and the answer is to fit a curve that turns those numbers into a chance between zero and one.

Logistic regression is a supervised machine learning method for classification, which means it learns from examples that already carry the right answer. Given data where each example is labelled yes or no, it finds the weights that best separate the two groups, and then uses those weights to score new examples it has never seen.

The idea is simple: draw a line, then bend it into a probability. A linear model can produce any number, including impossible ones such as a chance of 140 per cent, so logistic regression passes its output through a curve called the sigmoid, which squeezes every value into the range from zero to one. This article explains what logistic regression is, how it works, and where it is used.

Key takeaways

  • Logistic regression predicts categories, usually yes or no, as probabilities.
  • It uses the sigmoid curve to turn any number into a chance from zero to one.
  • It learns weights from labelled examples, like linear regression does.
  • A threshold, usually 0.5, turns the probability into a final decision.
  • It suits problems where the answer must be explainable as well as accurate.

What logistic regression is

Logistic regression models the probability that an example belongs to a class, rather than the class itself. For each input, such as the words in an email or the income of a borrower, the model learns a weight, multiplies each input by its weight, adds them up, and passes the total through the sigmoid curve. The result is a number between zero and one, read as the probability of the positive class.

The weights are the explanation. A large positive weight means that input pushes the answer towards yes, a large negative weight pushes it towards no, and a weight near zero means the input barely matters. That is why logistic regression is trusted in regulated work: a loan officer, a doctor, or an auditor can read the weights and see exactly which factors drove a decision, and by how much.

Despite its name, logistic regression is a classification method, not a regression method. It is called regression because it is built on the same mathematics as linear regression, fitting weights to data, but its output is a probability used to choose a class. Our guide to linear regression explains the model it is built on, and our guide to decision trees explains the rule-based model most often compared with it.

How logistic regression works

Training starts with labelled data: a table of examples, each with inputs and a known yes or no. The model begins with weights of zero, or small random values, and then improves them step by step, usually with gradient descent, following the slope of the error downhill until the weights separate the two classes as cleanly as they can.

The error is measured by a loss function called log loss, or cross-entropy. A confident wrong answer is punished far more than a cautious wrong answer, which pushes the model towards probabilities that are honest about their uncertainty, rather than extreme guesses. Over many passes through the data, the weights settle where the total loss is smallest.

Once trained, the model scores a new example by computing its weighted sum and passing it through the sigmoid curve. A score of 0.9 means the model is fairly sure the answer is yes, a score of 0.1 means it is fairly sure the answer is no, and a score near 0.5 means it genuinely cannot tell, which is itself useful information.

The final decision comes from a threshold, usually 0.5: above it the answer is yes, below it the answer is no. But the threshold can be moved. A spam filter might use 0.9, so that only obvious spam is blocked, while a medical screening test might use 0.2, so that almost no real case is missed, accepting more false alarms in exchange.

Logistic regression can also handle more than two classes. The usual method is one-versus-rest, where a separate model is trained for each class against all the others, and the class with the highest probability wins. A related method, multinomial logistic regression, fits all the classes at once, which is cleaner when there are many of them.

A laptop on a dark desk with its screen showing a glowing green curve dividing data points into two groups
A laptop showing a glowing green curve dividing data points into two groups shows how logistic regression works: numbers in, a probability out.

Comparing logistic regression with other models

Logistic regression is one of several classification models, and each suits a different problem. Linear regression predicts numbers rather than categories, decision trees split data into branches, and neural networks learn complex curves, but each has its own trade-offs.

The table below sets out the main contrasts between the leading approaches.

Aspect Logistic regression Linear regression Decision trees
Predicts Categories, yes or no Numbers, on a line Categories or numbers
Output Probability from zero to one A number, any value A category or number
Boundary A straight line A straight line A set of splits
Interpretability Clear, weights explain Very clear, slopes explain Clear, rules can be read
Best for Simple yes-or-no decisions Predicting numbers Rules and categories

The practical result is that logistic regression is the right choice when the answer is a category and the reasoning must be readable, linear regression wins when the answer is a number, and decision trees are the choice when the rules themselves matter most.

Where logistic regression is used

Credit scoring is the classic use. A bank models the chance that a borrower will default from income, debts, and repayment history, and the weights show exactly which factors matter, which is why regulators accept the model where a black box would not be. The score becomes a probability, and the bank sets its threshold where the business can afford the risk.

Medicine uses logistic regression to estimate risk. A model might predict the chance of a disease from age, blood pressure, and test results, and the probability helps doctors decide who needs further tests. Because the weights are readable, clinicians can check that the model agrees with medical knowledge, rather than trusting a number they cannot inspect.

Marketing uses it to predict who will respond. A retailer scores customers by past purchases, visits, and demographics, and sends offers to those most likely to buy, which saves money compared with mailing everyone. The threshold is tuned to the cost of the offer against the value of a sale.

Spam filtering was one of its earliest successes. Each word in an email becomes an input, the model learns which words signal spam, and a new message is scored and blocked when its probability passes the threshold. Modern filters use more complex models, but logistic regression remains the baseline they are measured against.

Churn prediction uses logistic regression to spot customers about to leave. A telecom or subscription service models the chance of cancellation from usage, complaints, and tenure, and the team intervenes with the customers the model flags, offering a discount or a call before the account is closed.

Strengths and limits

The greatest strength of logistic regression is its transparency. The model is a short list of weights, and anyone can read them: each weight says how much one input moves the probability, in which direction, and by how much. That makes it easy to explain, to trust, and to defend in front of people who are not specialists.

It is also a strength that logistic regression is fast and reliable. It trains in seconds, needs little data, gives calibrated probabilities rather than bare labels, and its mathematics is well understood, which is why it is often the first classifier tried, and the baseline that fancier models must beat.

The limits are real, though. Logistic regression draws a straight boundary between classes, so it cannot capture curves or interactions unless the inputs are transformed first, and it assumes the inputs are not too closely related to each other. When the boundary is genuinely curved, trees or neural networks will do better.

Logistic regression checklist

  • Check the classes are balanced, or adjust for imbalance first.
  • Scale the inputs, so the weights can be compared fairly.
  • Remove inputs that duplicate each other, since they confuse the weights.
  • Choose the threshold by cost, not by habit: 0.5 is not always right.
  • Check calibration, so a probability of 0.8 really happens eight times in ten.
  • Use regularisation when you have many inputs or little data.
  • Report precision and recall, not just accuracy, on the test set.
  • Read the weights, and check they make sense before you deploy.
  • Retrain regularly, since the world the model describes keeps changing.

Frequently asked questions

What is logistic regression in simple terms?

Logistic regression is a way of answering yes-or-no questions with a probability. It weighs the inputs, adds them up, and squeezes the result through a curve into a chance between zero and one, which is then turned into a decision.

What is the sigmoid function?

It is the curve that turns any number into a probability. Large positive numbers become close to one, large negative numbers become close to zero, and zero becomes exactly 0.5, which is why it is the natural bridge between a linear model and a yes-or-no answer.

What is the difference between linear and logistic regression?

Linear regression predicts a number, such as a price, while logistic regression predicts a category, such as yes or no, by turning its output into a probability. They share the idea of fitting weights to data, but their outputs and their loss functions differ.

What is a decision threshold?

It is the probability above which the model answers yes. The usual threshold is 0.5, but it can be moved: lower it to catch more positives at the cost of more false alarms, or raise it to be surer before saying yes.

When should I not use logistic regression?

When the boundary between classes is curved, when inputs interact strongly with each other, or when the relationship is too complex for a straight line. In those cases, trees, forests, or a neural network will do better.

Is logistic regression still used in machine learning?

Yes, widely. It is the baseline every new classifier is compared against, it is used wherever explanations matter, and it is often the right model when the data is small and the decision must be justified.

The bottom line

Logistic regression explained in one line is this: a weighted sum of the inputs, squeezed through a curve into a probability, and turned into a yes-or-no decision at a threshold you choose.

It is the oldest and simplest classifier in machine learning, and it endures because it is fast, transparent, and often good enough. Every data scientist starts here, and every complex classifier is judged against it.

This article is general information about how logistic regression works, not advice about building models for a particular problem.

Latest articles

Scroll to Top