Statistics & probability

Multinomial logistic regression calculator for several classes

Multinomial logistic regression fits several class probabilities jointly using a baseline-category softmax model.

Your numbers

Up to five design columns.
Every class from zero to K−1 must occur.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Multinomial logistic regression fits several class probabilities jointly using a baseline-category softmax model. Class zero is the reference and all other coefficient vectors describe log odds against it. This calculator uses an unpenalized Newton likelihood fit with explicit convergence, gradient and coefficient-growth checks.

THE FORMULAP(Y=k|x)=exp(x beta_k)/Σ_j exp(x beta_j), with beta_0=0.

A worked example

An intercept-only sample with class counts 2,3,5 has fitted probabilities 0.2,0.3,0.5. Coefficients against class zero are log(3/2) and log(5/2). The negative log likelihood is −2log(0.2)−3log(0.3)−5log(0.5), approximately 10.29653.

Good to know

Two to four consecutive classes beginning at zero, complete matched numeric observations and enough rows for the design. Supply an intercept column explicitly. Separation, singular design and diverging coefficients are rejected; no standard errors or causal claims.

The reference class anchors the parameterization

Class labels must be consecutive integers starting at zero, and every class must appear in the observations. The reference class has coefficient vector zero. Other vectors describe log probability ratios against that baseline; choosing another baseline changes coefficient representation while leaving the same fitted probabilities possible.

An intercept-only design produces class-frequency estimates, making the default a direct likelihood check. More predictors let the class odds change with observations. A column of ones must be entered explicitly when an intercept is wanted, because the design is used as supplied rather than modified silently by the calculator.

Multinomial intercept probabilities match observed class proportionsClass 00.2Class 10.3Class 20.5Counts 2, 3, 5 out of 10
An intercept-only sample with class counts 2,3,5 has fitted probabilities 0.2,0.3,0.5. Coefficients against class zero are log(3/2) and log(5/2). The negative log likelihood is −2log(0.2)−3log(0.3)−5log(0.5), approximately 10.29653.

The GLM regression calculator from response and design matrix covers the nearby task. Current binomial GLM only accepts two-class 0/1 responses; multinomial likelihood is jointly multiclass.

Probabilities are fitted jointly

Softmax normalization ensures probabilities for each observation sum to one. The implementation subtracts the largest linear predictor before exponentiating to reduce overflow. A tiny displayed class probability can still reflect floating-point rounding and is not an assertion that the class is logically impossible for that observation.

The Hessian contains cross-class terms because increasing one probability changes the others. Fitting independent binary models and renormalizing their outputs would not solve this same multinomial likelihood. The Newton calculation therefore updates all nonreference coefficient blocks together and checks the final likelihood gradient across the full parameter vector. A probability table remains indexed by the original class labels, so reference-class coefficients are not mistaken for missing probabilities.

Separation can prevent a finite likelihood estimate

A predictor pattern that perfectly separates classes can send an unpenalized coefficient toward infinity. More iterations do not create a finite maximum in that situation. Coefficient-growth, conditioning and optimization checks stop such fits with an error; adding a penalty would define a different model requiring an explicit implementation.

The page reports fitted probabilities and likelihood without standard errors or classification-performance claims. Training likelihood alone does not establish calibration on new observations. Reference comparisons align class order, reference category and intercept convention, then check the objective, score vector and per-observation probability sums rather than only one coefficient.

Translate softmax coefficients into class probabilities

Class zero is the reference class and has linear predictor zero. For each other class c, the entered design produces ηc=xβc. Probabilities are pc=exp(ηc)/(1+Σexp(ηj)) and p0=1/(1+Σexp(ηj)). A coefficient therefore changes the log odds of class c relative to class zero, holding the other design entries fixed.

A probability change is not equal to a coefficient: all class predictors share the denominator. Even a coefficient used in one class equation can change several probabilities. The implementation shifts exponentials during evaluation to avoid overflow, but that numerical stabilization does not make a separated likelihood have a finite maximum.

Recover class proportions with an intercept-only model

For ten observations with class counts 2,3,5, use ten design rows containing 1. The maximum-likelihood probabilities are 0.2,0.3,0.5. Relative to class zero, the two intercepts are log(0.3/0.2)=log(1.5)≈0.405465 and log(0.5/0.2)=log(2.5)≈0.916291. Substituting into the softmax denominator 1+1.5+2.5=5 reproduces the proportions.

As a second check, use counts 2,2,2: both nonreference intercepts are zero and each probability is one third. This balanced example does not imply that zero slopes are appropriate for richer data. Once predictors vary, fitted probabilities depend on each row and are no longer just the overall class proportions.

Construct class labels and predictors deliberately

Use consecutive labels 0,1,…,K−1 with every modeled class observed. Those labels identify unordered categories, not numeric distances between outcomes. A three-class model treats classes 0,1,2 as separate alternatives; it does not assume class two is twice class one. An ordinal response may call for a different model with a meaningful ordering assumption.

Enter a column of ones if you want intercepts. Indicator predictors for another categorical variable should omit a reference indicator when the intercept is present. Duplicate columns and redundant indicators make the coefficient problem singular. Keep a record of both reference choices so that coefficients from this form can be compared with coefficients reported elsewhere.

Distinguish fit convergence from useful classification

Perfect or near-perfect separation occurs when some predictor combination can push observed classes toward probability one while coefficients grow without bound. The form rejects divergence rather than presenting an arbitrarily large finite coefficient as a trustworthy estimate. Penalized multinomial regression is a possible alternative, but no penalty is silently introduced here.

For a converged fit, examine probability plausibility, class imbalance and performance on observations not used for fitting. A low training loss can coexist with poor probability calibration. This page fits the supplied design and displays its probabilities; it does not supply a confusion matrix, automatic decision threshold, cross-validation or standard errors. Choose those analyses according to the eventual decision, not merely the class with the largest fitted probability.

A few questions, answered

Which class is the reference?

Class zero has coefficient vector zero; other vectors are log odds against it.

Why can perfectly separated data fail?

An unpenalized maximum can require infinite coefficients, so a finite converged estimate may not exist.

Why is there no coefficient row for class zero?

Its linear predictor is fixed at zero to identify the model. The other coefficient rows describe log odds relative to that reference class.

Can ordered outcomes be entered as 0,1,2?

They can be represented as categories, but this multinomial model does not use their ordering. An ordinal model would make different assumptions.

Find your calculator

Start typing to explore the library.