Intuition The ONE core idea
Logistic regression takes a plain "yes-ness score" — a single number that can be anything from very negative to very positive — and bends it through an S-shaped slide so it lands between 0 and 1 , where we can read it as a probability . Everything else on the parent page is just the machinery for building that score, that slide, and the training rule that tunes them.
Before you can read the parent note comfortably, you must own every symbol it throws at you. Below, each symbol is introduced only after the ones it depends on. We start from a bare number line.
Definition Interval notation and infinity
A number line is the ruler of all real numbers, stretching endlessly left (negative) and right (positive). We write:
[ 0 , 1 ] — every number from 0 to 1 , including the ends (square bracket = "door closed, endpoint allowed").
( 0 , 1 ) — the same stretch but excluding the ends (round bracket = "door open, endpoint not allowed").
( − ∞ , ∞ ) — the whole number line. The symbol ∞ ("infinity") is not a number; it is shorthand for "keeps going with no wall".
Figure s01 — two homes. The picture below sets up the entire story: the top cyan line is the wide home ( − ∞ , ∞ ) where a raw score lives; the amber box is the narrow home [ 0 , 1 ] where a probability must live. Watch the white arrow — the whole job is to move a number from the line into the box.
Intuition Why the topic needs this
A probability is a fraction of certainty: 0 = "never", 1 = "certain", 0.5 = "coin flip". So probabilities must live in [ 0 , 1 ] . But a linear score can be anything — it lives in ( − ∞ , ∞ ) . The entire drama of logistic regression is moving a number from the wide line into the narrow box . You cannot follow that story without seeing these two homes side by side.
Definition Feature, feature vector, and how many features
n
A feature is one measured number describing a thing (e.g. a tumor's size). We write features as x 1 , x 2 , … ; the subscript j in x j just names which feature ("the j -th one").
The letter n is the number of features — how many measurements each example carries. So the features run x 1 , x 2 , … , x n , and j can be any of 1 , 2 , … , n .
A feature vector x is the whole list x 1 , … , x n for one example, stacked together — think of it as a single arrow in an n -axis space where each axis is one feature.
Figure s02 — one example is one arrow. Below, a two-feature example (n = 2 ) is drawn as a cyan arrow reaching the amber point ( x 1 , x 2 ) . The dashed white lines show each component x 1 , x 2 as a coordinate along its own axis.
Intuition Why the topic needs this
Real decisions depend on many measurements at once (size AND age AND density). Bundling them into one arrow x lets us write one clean formula instead of dragging around a dozen separate letters. The picture: a point/arrow whose position in feature-space is the example we want to classify.
The letter m counts the examples (rows of data); the letters j and n concern features (n = how many features total, j = which one). Keep them separate — m is how many things, n is how many properties each thing has.
Definition The dot product
w ⊤ x
Each of the n features gets a weight w j — a dial saying "how much does this feature matter, and in which direction". The bias b is a baseline offset (the score when all features are zero).
The symbol w ⊤ x ("w transpose x") is the dot product : multiply each weight by its matching feature and add all n of them up:
w ⊤ x = w 1 x 1 + w 2 x 2 + ⋯ + w n x n .
The little ⊤ just flips the column of n weights on its side so the multiplication lines up — you can safely read w ⊤ x as "weighted sum of features".
Intuition Why the topic needs this — and why THIS tool
Why a weighted sum and not something fancier? Because it is the simplest way to combine many numbers into one while letting each contribute its own strength and sign. It is exactly the machine from Linear Regression , borrowed wholesale. The picture: sliders w j that tilt a straight ramp; z is your height on that ramp for a given x .
w ⊤ x as "w to the power x"
Why it feels right: superscripts usually mean powers.
The fix: here ⊤ is the transpose symbol, not an exponent. w ⊤ x is an addition-of-products, always producing one number.
e and e z
e ≈ 2.718 is a fixed constant (like π ). For a whole-number exponent, e 3 just means e ⋅ e ⋅ e . But z can be any real number, so "multiply e by itself z times" makes no literal sense for, say, z = 1.5 . The honest definition fills the gaps smoothly: e z is the value the running sum 1 + z + 2 z 2 + 6 z 3 + … settles down to (equivalently, the smooth curve that agrees with e ⋅ e ⋯ at whole numbers and never jumps). You do not need this series to use e z — just trust that it is one smooth, unbroken curve. Key facts you must see :
e 0 = 1 .
As z → + ∞ , e z → + ∞ (explodes upward).
As z → − ∞ , e z → 0 (never negative — it hugs zero from above).
e − z = e z 1 (a minus sign in the exponent means "flip it over").
Definition The natural logarithm
ln
ln is the inverse of e ( ⋅ ) : it answers "e to what power gives me this?" So ln ( e z ) = z and e l n u = u . It takes a strictly positive input and returns any real number.
Figure s03 — exp and log are mirror images. The cyan curve is e z (always above the axis); the amber curve is ln u (only defined for positive u ). They are reflections across the dashed white line y = x — that reflection is what "inverse" means. Note the marked points e 0 = 1 and ln 1 = 0 .
Intuition Why the topic needs these two — and why THESE tools
The topic must (a) squash the wide score into ( 0 , 1 ) and (b) turn products into sums in the loss. The exponential e z is the natural squasher because it is always positive and smoothly bridges 0 and ∞ ; the log is its perfect undo-button, which is why odds get "log-ged" and why the likelihood product becomes a sum. They are chosen precisely because they are inverses — every "log-odds → sigmoid" step is just ln and e cancelling.
e − z can be negative when z is negative."
The fix: e anything is always strictly positive. A negative exponent gives a small positive number (e − 2 ≈ 0.135 ), never a negative one. This is exactly why the sigmoid can never dip below 0 or above 1 .
Definition Probability, odds, log-odds
Probability p = P ( y = 1 ∣ x ) reads "the chance the answer is yes (class 1 ), given the features x ". Lives in [ 0 , 1 ] .
Odds = 1 − p p — "how many times more likely yes than no". For p strictly between 0 and 1 this lives in ( 0 , ∞ ) : 0.5 probability → odds 1 (even); 0.75 → odds 3 ("3 to 1 on").
Log-odds (the logit ) = ln 1 − p p — take the log of the odds. Lives in ( − ∞ , ∞ ) .
Common mistake The edge cases
p = 0 and p = 1 (why the ladder needs the OPEN interval)
Why it matters: watch what happens at the extremes.
If p = 1 (certain yes), then 1 − p = 0 , and 1 − p p = 0 1 blows up — odds → + ∞ , and ln of that is undefined (no finite number).
If p = 0 (certain no), then 1 0 = 0 , and ln 0 → − ∞ — again undefined.
The fix / the point: the log-odds ladder only works when p lives in the open interval ( 0 , 1 ) — never exactly 0 or 1 . And this is exactly the range the sigmoid produces: σ ( z ) approaches 0 and 1 but never reaches them. So the model can be as confident as it likes, yet never breaks the math.
Intuition Why the topic needs this ladder
This is the bridge that makes the whole model possible. Probability is trapped in a box, odds open one wall, and the log opens the other — landing us on the full number line where a linear score z also lives. That match of ranges is what lets the parent boldly set ln 1 − p p = z . The picture: a value climbing three ladders, each rung widening its range, until it can shake hands with z .
The symbol y is the true label : y = 1 means "actually yes", y = 0 means "actually no". Bar ∣ inside P ( y = 1 ∣ x ) means "given / conditional on".
σ
σ ( z ) = 1 + e − z 1 .
It is the finished slide that takes any z and returns a number in the open interval ( 0 , 1 ) .
Figure s04 — the S-shaped slide. Below is the sigmoid itself: a smooth S rising from near 0 on the far left to near 1 on the far right, passing through the amber dot at ( 0 , 0.5 ) . The steepest part is in the middle (near z = 0 ); the two tails flatten out. This shape is the "slide" every score rides down.
σ ′ ( z ) — the slope, with its explicit formula
The derivative σ ′ ( z ) is the slope of the sigmoid at height z — "if I nudge z a tiny bit, how fast does σ change?" A big slope = steep middle of the S; a slope near 0 = a flat tail. The sigmoid has a famously clean slope formula:
σ ′ ( z ) = σ ( z ) ( 1 − σ ( z ) ) .
In words: "the slope equals the output times one-minus-the-output". So at z = 0 where σ = 0.5 , the slope is 0.5 × 0.5 = 0.25 (steepest); far out in the tails where σ ≈ 0 or ≈ 1 , the slope shrinks to ≈ 0 (flat). You can read this steepness directly off Figure s04.
Intuition Why the topic needs the slope — and why the derivative tool
Training means rolling downhill on the cost surface (see Gradient Descent ). To know which way is downhill, you must know the slope — that is exactly what a derivative measures. No slope, no direction, no learning. The picture: a ball on a curved hill; the arrow of the slope tells it where to roll.
Definition The cross-entropy cost
J (its explicit formula)
J is a single number scoring how wrong the whole model currently is, averaged over all m examples. Its explicit form — the binary cross-entropy (log loss) — is:
J = − m 1 ∑ i = 1 m [ y i ln p i + ( 1 − y i ) ln ( 1 − p i ) ] , p i = σ ( z i ) .
Here i indexes the m examples. Read the bracket: if the true label y i = 1 only ln p i survives (rewarding a high predicted p i ); if y i = 0 only ln ( 1 − p i ) survives (rewarding a low p i ). The minus sign turns "reward" into a cost we can push downhill.
Recall Why cross-entropy (from
Maximum Likelihood Estimation and Cross-Entropy Loss )
Maximum Likelihood Estimation just means "pick the weights that make the observed labels most probable". Writing each label as a coin flip p i y i ( 1 − p i ) 1 − y i and multiplying over all examples gives the likelihood; taking ln turns the product into the sum above, and negating gives J . So J isn't arbitrary — minimizing this cross-entropy is the same as maximizing likelihood. You don't need the full derivation here; just know J is the "make the data most likely" cost.
Definition The gradient symbol
∂ and the explicit gradient formulas
The symbol ∂ ("partial") measures change for a function of many variables: ∂ w j ∂ J is "how fast does the cost J change if I wiggle only weight w j , holding the rest still". For this cost the gradients collapse to a strikingly clean form:
\frac{\partial J}{\partial b} = \frac{1}{m}\sum_{i=1}^{m}(p_i - y_i).$$
Both read "(prediction − target) × input", where the bias uses input $1$ (it has no feature attached, so its "$x$" is just $1$).
Intuition Why the topic needs this
Everything before this section only lets us evaluate a fixed model. J , its gradients, and α are how the model improves — the loop that tunes w , b until predictions match reality. The picture: a marble descending a bowl, one α -sized hop at a time.
Read this top-down; each line depends only on the ones above it.
Number line & intervals (§1) — gives us the two "homes" ( − ∞ , ∞ ) and [ 0 , 1 ] .
Feature vector x , count n (§2) — one example as an arrow.
Exponential e z & log ln (§4) — the squash/undo pair.
Weighted sum z = w ⊤ x + b (§3) — needs the feature vector; builds the raw score.
Probability p , odds, log-odds (§5) — needs ln ; the ladder from box to number line.
Sigmoid σ ( z ) (§6) — needs e and the log-odds ladder; inverts it, giving the model equation P ( y = 1 ∣ x ) = σ ( z ) .
Slope σ ′ ( z ) = σ ( 1 − σ ) (§6) — needs the sigmoid.
Cost J & gradients ∂ J / ∂ w j , ∂ J / ∂ b (§7) — needs the slope; drives Gradient Descent .
Trained logistic regression — the loop of §7 repeated until J is small.
Read each as a question; the part after ::: is the answer to check yourself.
What does a round bracket ( 0 , 1 ) mean versus a square one [ 0 , 1 ] ? Round = endpoints excluded ; square = endpoints included .
Is ∞ a number? No — it is shorthand for "grows without any wall".
What does x j denote, and what does n count? x j is the j -th feature ; n is the total number of features per example.
What does m count, versus n ? m = number of examples (rows); n = number of features (columns).
Read w ⊤ x in words. The dot product — weighted sum w 1 x 1 + ⋯ + w n x n , one number.
What is z and its range? The linear score w ⊤ x + b ; it ranges over ( − ∞ , ∞ ) .
What is e 0 , and the sign of e z for any z ? e 0 = 1 ; e z is always strictly positive .
For non-integer z , what does e z really mean? The value of the smooth series 1 + z + 2 z 2 + … — the continuous curve through the whole-number powers.
What does ln undo, and what inputs does it accept? The exponential (ln ( e z ) = z ); it accepts only strictly positive inputs.
Give odds and log-odds when p = 0.75 . Odds = 0.75/0.25 = 3 ; log-odds = ln 3 ≈ 1.10 .
Why must p stay in the open interval ( 0 , 1 ) ? At p = 1 odds blow up (ln undefined); at p = 0 , ln 0 → − ∞ — the logit only works strictly between.
What does P ( y = 1 ∣ x ) read as? The probability the label is class 1 given the features x .
Solve ln 1 − p p = z for p — what do you get? p = 1 + e − z 1 = σ ( z ) (the sigmoid).
State the full model equation in one line. P ( y = 1 ∣ x ) = σ ( w ⊤ x + b ) = 1 + e − ( w ⊤ x + b ) 1 .
What is the explicit derivative σ ′ ( z ) ? σ ( z ) ( 1 − σ ( z ) ) — "output times one-minus-output"; equals 0.25 at z = 0 .
Write the binary cross-entropy cost J . J = − m 1 ∑ i [ y i ln p i + ( 1 − y i ) ln ( 1 − p i )] with p i = σ ( z i ) .
What are ∂ J / ∂ w j and ∂ J / ∂ b ? m 1 ∑ i ( p i − y i ) x ij and m 1 ∑ i ( p i − y i ) — (pred−target)×input, bias input = 1 .
Write the update rules for w j and b . w j ← w j − α ∂ J / ∂ w j and b ← b − α ∂ J / ∂ b .
What role does α play? The learning rate — the size of each downhill step.