
Logistic Regression
You can already ask an AI to write you a logistic regression. The trouble starts with the name — it's a classifier, not a regression — and it doesn't stop there. The model hands back a set of coefficients and a headline accuracy no matter what, but the coefficients are in log-odds, a unit almost everyone misreads on sight, and the accuracy can be a mirage: predict the majority class on imbalanced data and you'll post 95% while missing every case you actually care about. This is the course that gives you that judgment.
Five parts, one algorithm, no gaps:
Part 1 — Intro. How the logistic function bends any real number into a probability between 0 and 1, why you can't just run least squares on a yes/no outcome, and what "log-odds" means — the units the coefficients actually live in. Least squares gives way to maximum likelihood: instead of minimizing squared error you maximize the probability of the labels you observed, over a landscape that has a single summit the fit reliably climbs to. The intuition before the notation.
Part 2 — By Hand. A complete worked example — and here logistic regression parts ways with linear: there's no closed form, so you watch it iterate. Pick starting coefficients, compute each row's linear predictor, push it through the logistic function to a predicted probability, score the log-likelihood, take one update step, and see the number climb. Then read the converged coefficients back out as odds ratios. Every probability and every step on the page. Nothing waved away, nothing left "as an exercise." You prove the algorithm to yourself.
Part 3 — In Excel. The same example built out in a spreadsheet you can open and poke at — a probability column, a log-likelihood cell, and Solver turned loose to maximize it so you watch the coefficients settle onto their maximum-likelihood values. Then see for yourself what moving the classification threshold off the default 0.5, or rebalancing the classes, does to precision and recall.
Part 4 — In Python. A clean, executable, verified reference implementation — both the from-scratch iterative fit you just did by hand and the library call that also returns standard errors, odds ratios, and p-values, so you have a known-good result to check any other code against.
Part 5 — With AI. A tested prompt that directs an AI assistant to carry this same algorithm to your problem, plus the understanding to catch it when it's wrong.
By the end you won't just have working code. You'll have followed the algorithm from first principles through a hand calculation, a spreadsheet, and production Python — so when you point an AI at your own classification problem, you'll know how to read the coefficients as odds ratios, choose a threshold on purpose instead of accepting 0.5, spot class imbalance and separation before they bite, and tell when a high accuracy is real rather than an artifact of the base rate.
Written for practicing engineers and STEM professionals who'd rather understand a method than trust a black box.