Multiclass Logistic
๐ฏ Purpose
This QuickRef covers multinomial (multiclass) logistic regression โ a generalization of binary logistic used when your target variable has 3 or more unordered classes.
๐ฆ 1. When to Use¶
Condition | Use Multiclass Logistic |
---|---|
Target has โฅ3 unordered categories | โ Yes |
Categories have no rank or order | โ Yes |
Binary target | โ Use standard logistic |
Ordered categories (low < med < high) | โ Use ordinal logistic |
Examples: Customer segments, product types, political affiliation
๐งฎ 2. Model Logic (Softmax Function)¶
$$ P(Y = k \mid X) = \frac{\exp(X \cdot \beta_k)}{\sum_{j=1}^{K} \exp(X \cdot \beta_j)} $$
Each class k has its own coefficient vector ฮฒ_k
, compared to a baseline (reference) class.
๐ ๏ธ 3. Fitting the Model¶
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(multi_class='multinomial', solver='lbfgs')
clf.fit(X_train, y_train)
# statsmodels implementation
import statsmodels.api as sm
model = sm.MNLogit(y, sm.add_constant(X)).fit()
โ๏ธ Use predict_proba()
for class probabilities
๐ 4. Output Interpretation¶
Output | Meaning |
---|---|
coef_ |
Log-odds of class k vs reference |
np.exp(coef_) |
Odds ratio for each class vs baseline |
predict_proba() |
Class probability distribution per row |
โ ๏ธ 5. Assumptions¶
Assumption | Notes |
---|---|
Independence of Irrelevant Alternatives (IIA) | Assumes relative odds between any two categories do not depend on the presence of others |
No ordering | Categories must be nominal, not ordinal |
โ Modeling Checklist¶
- [ ] Confirm target is nominal (unordered, โฅ3 classes)
- [ ] Model fit using
multi_class='multinomial'
and proper solver (e.g. lbfgs) - [ ] Probabilities interpreted using softmax logic
- [ ] Log-odds and odds ratios clearly reported
- [ ] IIA assumption acknowledged or tested (esp. in
statsmodels
)
๐ก Tip¶
โBinary logistic picks yes/no. Multiclass logistic asks: which one?โ