DS701 Session 13 — Mon Oct 19, 2026
Write down the logistic regression model: what linear function does it fit, what quantity is that linear function equal to, and how do you get from it to a probability \(p(y{=}1 \mid x)\)? Then say how the coefficients are chosen (which principle) and why, unlike linear regression, they cannot be found in closed form.
In the admissions fit, \(\hat\beta_{\text{gpa}} = 0.777\). A classmate reads this as “one more GPA point raises the probability of admission by 0.777”. What does the coefficient actually say, what does \(e^{0.777} \approx 2.17\) mean, and why is there no single change in probability?
To turn logistic regression into a classifier the lecture used the rule “say yes if \(p(y{=}1 \mid x) > t\)” and found on the admissions data that F1 peaked near \(t \approx 0.35\), not \(0.5\). Explain what lowering the threshold does to precision and to recall, why \(0.5\) is not automatically the right choice, and give one real setting where you would deliberately pick a low threshold and one where you would pick a high one.
Last lecture: a continuous \(y\) as a linear function of \(x\). Today: a 0/1 \(y\), and we want a probability.

One observation: \(\;\text{P}(y_i \mid x_i) = p_i^{\,y_i}\,(1-p_i)^{1-y_i}, \qquad p_i = \sigma(\boldsymbol{\beta}^\top\mathbf{x}_i).\)
statsmodels.Logit / sklearn.LogisticRegression do the climb for you and give a coefficient per feature (plus the column of ones for \(\beta_0\)).Today’s activity, Part 1: you write \(\sigma\), \(\ell\), and one gradient step by hand — then check that sklearn lands in the same place.

Admissions: F1 peaks near \(t \approx 0.35\) — the model rarely says “admit” at 0.5 because admits are the minority (and “always reject” is already 68% accurate).

ROC: TPR vs FPR, one point per threshold; diagonal = random; AUC summarizes ranking quality without choosing a threshold (0.71 on the held-out split).
AUC tells you how good the scores are. It does not tell you where to cut.
class_weight="balanced" re-weights the fit so both classes count equally — a cost ratio set by the class frequencies, not by what the mistakes actually cost.Today’s case study ends on exactly that cut: the lending desk’s approval threshold, from the costs they state.
sklearn’s LogisticRegression() penalizes by default, with C \(= 1/c\). 11B explains what that knob does.The client: a Massachusetts credit union’s small-business lending desk.
The data: a simulator of the desk’s applicants, whose true answer you know
class_weight="balanced"Report out: a two-sentence memo to the desk — which threshold, and the one caveat they must hear.
numpy, pandas, matplotlib, scikit-learn.The activity notebook goes live on the day of the lecture. Colab is optional — you can also open it on GitHub and run it locally.
Full lecture notes: Logistic Regression