故事 · Verhulst 的 S 曲线,从人口到分类
Origin Story · Verhulst's S-Curve, From Populations to Classifiers
1838 年,比利时数学家 Pierre Verhulst 研究人口增长,发现它不会无限指数膨胀,而是先快后慢、最终趋于饱和 ——
画出来是一条优雅的 S 形(logistic)曲线。一个多世纪后,统计学家借用了这条曲线的形状:
线性回归预测概率会冲破 0 和 1,而 sigmoid 天生被夹在 [0, 1] 之间,简直是为「概率」量身定做。
于是 逻辑回归 诞生:先用线性式 β₀+β₁x 算出 logit(对数赔率),再用 sigmoid 翻译成概率。
它最迷人的副产品是 优势比 e^(β₁) —— 医学论文里「吸烟者患病的 OR=2.3」说的就是它:吸烟让患病赔率翻 2.3 倍。
In 1838, the Belgian mathematician Pierre Verhulst was studying how populations grow. He noticed that growth never explodes exponentially forever — it accelerates,
then slows, then saturates. Plotted, that trajectory is an elegant S-shaped logistic curve. More than a century later, statisticians borrowed that exact shape:
linear regression cheerfully overruns 0 and 1, while the sigmoid is naturally trapped between [0, 1] — practically tailor-made for probabilities.
That gave us logistic regression: feed the linear combination β₀ + β₁x through the sigmoid, getting first the logit (log-odds) and then a clean probability.
Its most charming byproduct is the odds ratio e^(β₁) — when a medical paper reports "smokers have an OR of 2.3 for disease X," it means smoking multiplies the odds by 2.3.
1 S 形曲线 · 把 0/1 点压进概率 The S-Curve · Squashing 0/1 Points into Probabilities
β₁=1.002 为什么不能用直线:概率会冲出 [0, 1] Why Not a Straight Line: Probability Breaks Out of [0, 1]
红色直线是线性回归的预测:它在两端无情地冲破 0% 和 100%,给出 −20% 或 130% 这种荒谬概率。 蓝色 sigmoid 则始终被锁在灰色合法区间内 —— 这就是逻辑回归存在的根本理由。 The red line is the linear-regression prediction: at both ends it blows straight through 0% and 100%, returning nonsense like −20% or 130%. The blue sigmoid stays locked inside the gray legal band — and that is precisely why logistic regression exists.
3 现实里的逻辑回归 Logistic Regression in the Real World
二分类:邮件是否垃圾、用户是否点击、患者是否阳性 —— 凡是「是/否」结果,逻辑回归都是起手式。
Binary classification: spam or ham, click or skip, positive or negative — whenever the outcome is yes/no, logistic regression is the default first move.
违约/流失预测:银行用它估「这笔贷款违约的概率」、企业用它估「这个客户下月流失的概率」。
Default and churn scoring: banks use it to estimate "probability this loan defaults"; SaaS teams use it to estimate "probability this customer churns next month."
优势比 OR:e^β 让系数可解释——「年龄每增 10 岁,患病赔率 ×2.3」,医学与风控论文的标准语言。
Odds ratio: e^β makes coefficients tellable — "every additional 10 years of age multiplies the odds of disease by 2.3" is the standard dialect in medical and credit-risk papers.
概率压缩:sigmoid 把任意分数压进 0-1,既是合法概率,又能配阈值(不一定是 0.5)灵活调召回/精度。
Probability squashing: the sigmoid forces any score into [0, 1] — a valid probability you can pair with a tunable threshold (not necessarily 0.5) to trade recall against precision.
一句话In One Line
逻辑回归其实是「在 logit 空间里做线性回归」。它不直接预测概率 p,而是预测
logit(p) = ln(p/(1−p)) —— 也就是「对数赔率」,这个量可以自由取任意实数,正好配线性式 β₀+β₁x。
再用 sigmoid 把它逆变换回 [0, 1] 的概率。所以系数的真正含义在赔率上:
x 每涨 1,logit 涨 β₁,赔率就乘以 e^(β₁) —— 这就是优势比。β₁>0 曲线上升、β₁<0 下降、|β₁| 越大 S 越陡。
决策边界 p=0.5 落在 logit=0,即 x = −β₀/β₁。它的灵魂就一句话:概率不能用直线,必须用 S 曲线把它关进笼子。
Logistic regression is really linear regression performed in logit space. It does not predict the probability p directly; it predicts
logit(p) = ln(p/(1−p)) — the log-odds — which is free to take any real value and therefore fits a linear form β₀ + β₁x perfectly.
The sigmoid then inverts that back into a probability in [0, 1]. So the real meaning of the coefficients lives on the odds scale:
every +1 in x raises the logit by β₁ and multiplies the odds by e^(β₁) — that is the odds ratio. β₁ > 0 lifts the curve, β₁ < 0 lowers it, and a larger |β₁| makes the S steeper.
The decision boundary p = 0.5 lands at logit = 0, i.e. x = −β₀ / β₁. The whole soul of the method in one line: probability won't fit a straight line — cage it inside an S-curve.
常见误用Common Mistakes
对二分类硬用线性回归。线性回归会预测出 <0 或 >1 的非法概率,分类问题该用逻辑回归的 sigmoid。
Forcing linear regression onto a binary outcome. Linear regression will hand back probabilities < 0 or > 1 — for classification, use the logistic sigmoid.
把系数 β₁ 直接当概率变化。β₁ 是 logit 的变化;要谈赔率得取 e^β(优势比),谈概率还得看所处位置(S 曲线非线性)。
Reading β₁ as a direct change in probability. β₁ is the change on the logit scale. Exponentiate to e^β for the odds ratio; the probability change depends on where you are on the (nonlinear) S-curve.
不平衡数据也死守 0.5 阈值。正负样本悬殊或代价不对称时,应按业务调阈值,并看 ROC/召回而非只看准确率。
Sticking to a 0.5 threshold on imbalanced data. When class ratios or misclassification costs are skewed, tune the threshold to the business and look at ROC / recall rather than raw accuracy.