Formula Bro

Math and physics formulas, explained like you are new.


Logistic Regression

In one sentence: Logistic regression takes the same weighted sum as a straight line, then squeezes it through an S-shaped curve so the result is a probability between 0 and 1 for a yes-or-no question.

p=σ(wx+b)=11+e−(wx+b)p = \sigma(w x + b) = \frac{1}{1 + e^{-(w x + b)}}

Read it out loud: “p equals sigma of w x plus b, which equals one over one plus e to the power of minus the quantity w x plus b. Here p is the probability of class 1, sigma is the sigmoid curve, w is the weight, x is the input, b is the bias, and e is Euler's number, about 2.718.”

Before you start

The ideas and signs this page uses, explained from zero. For powers of ten, Greek letters and other notation in general, see Math basics.

Probability between 0 and 1, and percent

A probability is a number from 0 to 1 that says how likely an outcome is. 0 means it cannot happen, 1 means it is certain, and 0.5 means an even chance. Multiply by 100 to read it as a percentage, so 0.731 is 73.1 percent. A logistic regression model gives a probability for each new case, and the answer is never more than 1 or less than 0.

The sigmoid, and the Greek letter σ\sigma (sigma)

The Greek letter σ\sigma, said SIG-muh, is used here as the name of a rule, the sigmoid. It takes any number, positive, negative or zero, and returns a value between 0 and 1. A graph of it looks like a stretched letter S, which is where the name comes from. Writing σ(z)\sigma(z) means ‘apply the sigmoid to the number zz’.

Euler’s number ee and negative exponents

The letter ee is a fixed number, about 2.71828, called Euler’s number. exe^{x} means ee raised to the power xx, so e1≈2.718e^{1} \approx 2.718 and e2≈7.389e^{2} \approx 7.389. A minus sign in the exponent means divide: e−x=1exe^{-x} = \frac{1}{e^{x}}. So e−1=12.718≈0.368e^{-1} = \frac{1}{2.718} \approx 0.368, which is a small positive number.

Odds and log-odds

Odds compare the chance of an outcome with the chance it does not happen. If the probability of passing is 0.75, the odds are 3 to 1, because passing is three times as likely as failing. The log-odds, the raw score z=wx+bz = w x + b in this model, is the logarithm of the odds. It can be any number, and the sigmoid turns it into a probability.

A threshold

A threshold is a cutoff number that turns a probability into a decision. With a threshold of 0.5, the model says ‘yes’ whenever the probability is 0.5 or more, and ‘no’ otherwise. The threshold is a choice made by the person using the model, and it can be set higher or lower depending on whether false alarms or misses cost more.

What each symbol means

SymbolMeaning

pp

The probability that the outcome is class 1, for example that a student passes. It is always between 0 and 1, and multiplying by 100 gives a percentage. It has no unit, because it is a share of all the cases.

σ\sigma

The sigmoid function, also called the logistic function. It takes any real number and returns a value strictly between 0 and 1. It is a fixed rule, not a number you learn, and it is what turns the raw score into a probability.

ww

The weight, the number that says how strongly the input pushes the probability up or down. A positive weight means a larger xx gives a higher probability. In the example, w=0.8w = 0.8 means each extra hour of study adds 0.8 to the raw score. Its unit is the unit of the score divided by the unit of xx.

xx

The input, a number you measure for each case, such as hours of study. Its unit depends on what you measure, and in the example it is hours. The model uses xx together with ww and bb to produce the probability.

bb

The bias, also called the intercept. It shifts the whole curve left or right, and it sets the input value where the probability crosses 0.5. Its unit is the same as the raw score, which has no everyday unit in most models. In the example, b=−3b = -3.

ee

Euler’s number, a fixed value of about 2.71828. It appears in the formula because the sigmoid is built from exponentials, and raising ee to a negative power produces the smooth S-shaped curve. It has no unit.

The formula piece by piece

wxw x

Start with the input scaled by the weight. Multiplying the input by ww says how strongly this input pushes the answer, so a bigger xx with a positive ww gives a bigger push toward class 1.

wx+bw x + b

Add the bias to the weighted input. The result is the raw score, also called the log-odds, which can be any number. It is exactly the same weighted sum that a straight-line model would use, and it is still not a probability.

e−(wx+b)e^{-(w x + b)}

Compute ee raised to the negative of the raw score. This number is always positive. It is close to 0 when the raw score is large and positive, and it is large when the raw score is large and negative. This is the step that makes the curve bend.

11+e−(wx+b)\frac{1}{1 + e^{-(w x + b)}}

Add 1 to the positive number and divide 1 by the total. The answer is always between 0 and 1: near 1 for a large positive raw score, near 0 for a large negative one, and exactly one half when the raw score is 0.

p=σ(wx+b)=11+e−(wx+b)p = \sigma(w x + b) = \frac{1}{1 + e^{-(w x + b)}}

The whole formula in one sentence: the probability of class 1 equals the sigmoid of the weighted input plus the bias, which is one divided by one plus ee raised to the minus of that weighted sum.

What the formula is doing, and why

Linear regression predicts a number, but many questions have a yes-or-no answer: will the student pass, is the email spam, will the loan be repaid. For these you want a probability. Logistic regression starts from the same weighted sum as a straight line, z=wx+bz = w x + b, and then passes it through the sigmoid function σ(z)=11+e−z\sigma(z) = \frac{1}{1 + e^{-z}}. The value zz is the raw score, which is also called the log-odds, and it can be any size.

What does the sigmoid do? It does the squeezing. When zz is a large positive number, e−ze^{-z} is tiny and the output is close to 1. When zz is a large negative number, e−ze^{-z} is huge and the output is close to 0. When zz is exactly 0, the output is exactly 0.5. The curve rises smoothly between those extremes, so a small change in the input gives a small change in the probability.

How are ww and bb learned? The weights ww and bb are learned from labeled examples, where the true answer is known for each case. They are chosen to make the observed answers as likely as possible, a rule called maximum likelihood. For this kind of model that rule is the same as making the cross-entropy loss as small as possible. Once the model is trained, a yes-or-no answer comes from a threshold: predict class 1 when p≥0.5p \ge 0.5 and class 0 otherwise. Because σ(0)=0.5\sigma(0) = 0.5, that rule is the same as asking whether wx+b≥0w x + b \ge 0.

Why not always use 0.5? The threshold of 0.5 is a default, not a law. When a false alarm costs more than a miss, as in some medical screening, a different threshold is wiser. With one input, the boundary between the two classes is the single point where z=0z = 0, which is x=−b/wx = -b / w.

An everyday picture

Think of a sliding scale that runs from very unlikely to very likely. The weighted sum is a raw score that can be any size, like points on a scoreboard. The sigmoid is the translator that turns any score into a position on the 0 to 100 percent scale. A score of zero lands exactly in the middle, at 50 percent.

Worked example: Will a student pass a test after studying?

A model uses hours studied xx. It has learned the weight w=0.8w = 0.8 per hour and the bias b=−3b = -3. We find the probability of passing for a student who studies 5 hours and for one who studies 2 hours. We use a threshold of 0.5. The probabilities are made up for this example to show the method.

  1. Compute the raw score for 5 hours. The weighted sum is z=0.8×5−3=4−3=1.0z = 0.8 \times 5 - 3 = 4 - 3 = 1.0. Each hour adds 0.8 to the score, and the bias takes away 3, so this student has a raw score of 1.0.
  2. Find e−ze^{-z} for this score. The formula needs e−1.0e^{-1.0}, which equals 1e1.0=12.718≈0.368\frac{1}{e^{1.0}} = \frac{1}{2.718} \approx 0.368. Because the raw score is positive, the number is less than 1, which means the probability will be above one half.
  3. Apply the sigmoid. The probability is p=11+e−1.0=11+0.368≈0.731p = \frac{1}{1 + e^{-1.0}} = \frac{1}{1 + 0.368} \approx 0.731. Multiplying by 100 gives 73.1 percent, the chance that this student passes.
  4. Compare with the threshold. Since 0.731≥0.50.731 \geq 0.5, the model predicts pass for this student. The threshold is the cutoff that turns the probability into a yes-or-no decision.
  5. Repeat the steps for 2 hours. The raw score is z=0.8×2−3=1.6−3=−1.4z = 0.8 \times 2 - 3 = 1.6 - 3 = -1.4. The student has studied less, so the raw score is negative.
  6. Apply the sigmoid to the negative score. The minus sign in e−ze^{-z} becomes plus, so we need e1.4≈4.055e^{1.4} \approx 4.055. Then p=11+4.055≈0.198p = \frac{1}{1 + 4.055} \approx 0.198. Multiplying by 100 gives 19.8 percent.
  7. Compare again, and find the boundary. Since 0.198<0.50.198 < 0.5, the model predicts fail for the 2-hour student. The boundary is where the raw score is exactly zero, so 0.8x−3=00.8x - 3 = 0, which gives x=30.8=3.75x = \frac{3}{0.8} = 3.75 hours.

Answer: A student who studies 5 hours has about a 73.1% chance of passing, so the model predicts pass. A student who studies 2 hours has about 19.8%, so the model predicts fail. The 0.5 boundary falls at 3.75 hours of study, where the raw score is zero.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

How is logistic regression different from linear regression?

Linear regression predicts a number, such as a price. Logistic regression predicts a probability for a class, and the sigmoid keeps the output between 0 and 1.

Why is it called logistic?

The sigmoid curve it uses is also called the logistic function, and that is where the name comes from.

Can the output ever be exactly 0 or 1?

Not in exact arithmetic. The sigmoid gets very close to 0 for large negative scores and very close to 1 for large positive scores, but it never reaches either end.

Can logistic regression handle more than two classes?

Yes. The method is extended to several classes, usually by using softmax in place of the sigmoid.

Sources

  1. Logistic regression, Wikipedia
  2. Logistic function, Wikipedia

| All AI & ML formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: ai-ml/logistic-regression.md.