2.2.9 · D1Linear & Logistic Regression

Foundations — Logistic regression and the sigmoid function

3,105 words14 min readBack to topic

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.


1. Numbers, intervals, and the symbol

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 where a probability must live. Watch the white arrow — the whole job is to move a number from the line into the box.

Figure — Logistic regression and the sigmoid function

2. A feature vector and its components ; the count

Figure s02 — one example is one arrow. Below, a two-feature example () is drawn as a cyan arrow reaching the amber point . The dashed white lines show each component as a coordinate along its own axis.

Figure — Logistic regression and the sigmoid function

The letter counts the examples (rows of data); the letters and concern features ( = how many features total, = which one). Keep them separate — is how many things, is how many properties each thing has.


3. Weights , bias , and the linear score


4. The exponential and the natural log

Figure s03 — exp and log are mirror images. The cyan curve is (always above the axis); the amber curve is (only defined for positive ). They are reflections across the dashed white line — that reflection is what "inverse" means. Note the marked points and .


5. Probability , odds, and log-odds (the logit)

The symbol is the true label: means "actually yes", means "actually no". Bar inside means "given / conditional on".


6. The sigmoid and the model equation

Figure s04 — the S-shaped slide. Below is the sigmoid itself: a smooth S rising from near on the far left to near on the far right, passing through the amber dot at . The steepest part is in the middle (near ); the two tails flatten out. This shape is the "slide" every score rides down.


7. Cost , its gradient, and the training loop

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 and multiplying over all examples gives the likelihood; taking turns the product into the sum above, and negating gives . So isn't arbitrary — minimizing this cross-entropy is the same as maximizing likelihood. You don't need the full derivation here; just know is the "make the data most likely" cost.


Prerequisite outline (what feeds what)

Read this top-down; each line depends only on the ones above it.

  1. Number line & intervals (§1) — gives us the two "homes" and .
  2. Feature vector , count (§2) — one example as an arrow.
  3. Exponential & log (§4) — the squash/undo pair.
  4. Weighted sum (§3) — needs the feature vector; builds the raw score.
  5. Probability , odds, log-odds (§5) — needs ; the ladder from box to number line.
  6. Sigmoid (§6) — needs and the log-odds ladder; inverts it, giving the model equation .
  7. Slope (§6) — needs the sigmoid.
  8. Cost & gradients (§7) — needs the slope; drives Gradient Descent.
  9. Trained logistic regression — the loop of §7 repeated until is small.

Equipment checklist

Read each as a question; the part after ::: is the answer to check yourself.

What does a round bracket mean versus a square one ?
Round = endpoints excluded; square = endpoints included.
Is a number?
No — it is shorthand for "grows without any wall".
What does denote, and what does count?
is the -th feature; is the total number of features per example.
What does count, versus ?
= number of examples (rows); = number of features (columns).
Read in words.
The dot product — weighted sum , one number.
What is and its range?
The linear score ; it ranges over .
What is , and the sign of for any ?
; is always strictly positive.
For non-integer , what does really mean?
The value of the smooth series — the continuous curve through the whole-number powers.
What does undo, and what inputs does it accept?
The exponential (); it accepts only strictly positive inputs.
Give odds and log-odds when .
Odds ; log-odds .
Why must stay in the open interval ?
At odds blow up ( undefined); at , — the logit only works strictly between.
What does read as?
The probability the label is class given the features .
Solve for — what do you get?
(the sigmoid).
State the full model equation in one line.
.
What is the explicit derivative ?
— "output times one-minus-output"; equals at .
Write the binary cross-entropy cost .
with .
What are and ?
and — (pred−target)×input, bias input .
Write the update rules for and .
and .
What role does play?
The learning rate — the size of each downhill step.