M2-094M2: Classical Machine LearningLogistic Regression & GLMMedium
⚡Flashcard Drill➔Mastery:

Multinomial Logistic Regression (Softmax Regression) and Parameter Identifiability

🎯 Active Recall Self-Check (Draft First, Verify After)
Login-free practice tracker: recall core answer, audit pitfalls, and log review status.
Step 1 · Draft your concise answer & assumptions
Step 2 · Check Pitfalls & Follow-up Inquiries
Next: M2-095 →
📐 Mathematical Definition
P(y=k∣x)=ewk⊤x∑j=1Kewj⊤xP(y=k\mid x)=\frac{e^{w_k^\top x}}{\sum_{j=1}^{K}e^{w_j^\top x}}
⚡ One-Sentence Core Answer
Softmax regression generalizes logistic regression to KK classes; overparameterization requires fixing one class vector to zero (reference class) to ensure parameter identifiability.

📌 Key Takeaways

  • •
    Softmax formulation: P(y=k∣x)=exp⁡(wkTx)∑j=1Kexp⁡(wjTx)P(y = k \mid x) = \frac{\exp(w_k^T x)}{\sum_{j=1}^K \exp(w_j^T x)}
  • •
    Parameter redundancy: adding an arbitrary constant vector cc to all wkw_k leaves probabilities completely unchanged
  • •
    Identifiability fix: set wK=0w_K = 0, reducing free parameters from K×dK \times d to (K−1)×d(K-1) \times d

📐 Mathematical Derivations

Proof of Non-identifiability: Let P(y=k∣x)=exp⁡(wkTx)∑j=1Kexp⁡(wjTx)P(y = k | x) = \frac{\exp(w_k^T x)}{\sum_{j=1}^K \exp(w_j^T x)}.
If we replace each wkw_k with wk′=wk+cw'_k = w_k + c for any vector c∈Rdc \in \mathbb{R}^d:
P′(y=k∣x)=exp⁡((wk+c)Tx)∑jexp⁡((wj+c)Tx)=exp⁡(wkTx)exp⁡(cTx)∑jexp⁡(wjTx)exp⁡(cTx)=P(y=k∣x)P'(y = k | x) = \frac{\exp((w_k + c)^T x)}{\sum_j \exp((w_j + c)^T x)} = \frac{\exp(w_k^T x) \exp(c^T x)}{\sum_j \exp(w_j^T x) \exp(c^T x)} = P(y = k | x).
Because infinitely many parameter sets produce identical likelihoods, the Fisher information matrix is singular. To achieve statistical identifiability, set reference class wK=0w_K = 0. Then for k<Kk < K: log⁡(P(y=k∣x)P(y=K∣x))=wkTx\log\left(\frac{P(y=k|x)}{P(y=K|x)}\right) = w_k^T x.
In deep learning, all KK vectors are retained because L2 weight decay λ∑k∥wk∥22\lambda \sum_k \|w_k\|_2^2 implicitly resolves non-identifiability by selecting the minimum-norm solution.

🏭 Production Trade-offs

Engineering distinction: In classical statistics (e.g., R, statsmodels), setting wK=0w_K=0 is mandatory for parameter inference and p-values. In neural networks (PyTorch, TensorFlow), symmetric KK-vector parameterization with weight decay is standard because it simplifies GPU backpropagation.
⚠️ Common Interview Pitfalls
  • ✕
    Attempting to invert the unregularized Fisher information matrix of a KK-class softmax without fixing a reference class
  • ✕
    Interpreting softmax output probabilities as independent class likelihoods rather than constrained sum-to-one distributions
🎯 Interviewer Follow-up Inquiries
  • ?
    How does L2 regularization implicitly select the unique minimum-norm parameterization in overparameterized softmax?
  • ?
    What is the Independence of Irrelevant Alternatives (IIA) property in multinomial logit models?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

← PreviousM2-093: Interaction and Polynomial Terms in Regression: Formulations and Regularization📋 Back to BankNext →M2-095: Relationship Between Logistic Regression and the Maximum Entropy Model
中文速览与面试要点

解释多项逻辑回归(softmax 回归)与它的参数辨识性问题

用 softmax 输出 K 类概率;K 组参数不可唯一辨识,需固定参照类或加约束。

核心要点

  • 多项逻辑回归用 softmax 把 K 个线性得分转为概率。 辨识性问题的来源 :注意到对 所有 w_k 同时加上同一个向量 c,分子分母同乘 e^cᵀx 后概率不变——即参数存在 K 维的平移不变性 (实际是 K−1 维的冗余)。因此参数解不唯一,海森矩阵奇异,优化不收敛。 两种消除方式 :① 固定参照类 ——令 w_K=0(把第 K 类作为基准),此时参数为'相对基准类的 log-odds':log[P(k)/P(K)]=w_kᵀx,共 K−1 组参数,唯一可辨识;② 加 L2 正则 ——惩罚 Σ‖w_k‖² 使解唯一(且在数值上更稳定),此时不设参照类也可。 与 one-vs-rest 的区别 :OvR 训练 K 个独立的二分类器(可能给出概率和不为 1 的结果,需归一化),多项 LR 联合训练(概率天然和为 1,参数共享分母,统计上更正确)。
  • 实践要点:① 系数解释 ——在参照类参数化下,w_k 表示'特征每增 1 单位时,类 k 相对参照类的 log-odds 变化';优势比 e^w_kj 是相对基准类的优势倍数。② 正则化的必要性 ——若某类在训练集中样本极少或完全分离,未正则化的解会发散(同二分类的分离问题);L2 正则同时解决辨识性与分离问题。③ 计算 ——用交叉熵损失 + softmax,梯度形式简洁:∇_w_k=Σᵢ(p_ik−y_ik)xᵢ(与二分类形式一致);损失是凸的(唯一最优,前提是正则化或参照类约束)。④ 类别数很多时 ——K 很大(如万级)时 softmax 的分母计算昂贵(需遍历所有类),此时用 层次 softmax (树结构,O(log K))或 负采样 (近似,如 word2vec);这与推荐系统的'全量 softmax vs 采样'问题相同。⑤ 与神经网络的 softmax 层等价 ——多项逻辑回归 = 单层神经网络 + softmax 输出层,只是术语与优化方式不同。⑥ 类别不平衡 ——softmax 下可用类权重(损失加权)或先验调整(logit adjustment)。
  • 参数平移不变性:w_k ← w_k + c 不改变概率
  • 常用参照类(w_K=0)或 L2 正则消除歧义

常见陷阱

  • 不设参照类也不加正则(参数不唯一)
  • 用 OvR 的概率直接当作互斥类别概率(需归一化)