Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Logistic regression and conditional maximum-entropy classification are two ways to describe the same probabilistic classifier when they use the same features and an unregularized likelihood objective. Logistic regression emphasizes how a linear score becomes class probabilities; maximum entropy explains why that probability distribution is the least-committal one consistent with selected feature constraints.

This guide works through the binary and multiclass equations, shows how to interpret coefficients, and fits a model in Python. The key idea is simple: logistic regression is linear in the log-odds, not in the probability.

What logistic regression predicts

Logistic regression is a classification method, despite the word “regression” in its name. It estimates the probability of a categorical outcome from input features. For a binary outcome, let y be 1 for the event of interest and 0 otherwise. The model first calculates a linear score:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

z = β₀ + β₁x₁ + … + βₚxₚ = β₀ + βᵀx

#1 Best Overall
Design of Experiments: Statistical Principles of Research Design and Analysis
  • New
  • Mint Condition
  • Dispatch same day for order received before 12 noon
  • Guaranteed packaging
  • No quibbles returns

It converts that score to a probability with the sigmoid, or logistic, function:

P(y = 1 | x) = σ(z) = 1 / (1 + e⁻ᶻ)

The sigmoid keeps the result between 0 and 1. A score of 0 gives probability 0.5; positive scores give probabilities above 0.5, and negative scores give probabilities below it. Scikit-learn describes logistic regression as a linear classification model and also uses the names logit regression, maximum-entropy classification, and log-linear classifier in its linear-model documentation.

Why the name includes “regression”

The model applies a linear predictor to the log-odds of the outcome:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

log[p / (1 − p)] = β₀ + βᵀx

It is therefore linear in log-odds, not in probability. The model returns probabilities; a separate decision rule can turn them into class labels.

Odds, probability, and log-odds

Odds compare the probability of an event with the probability it does not occur. Log-odds are the natural logarithm of those odds. These conversions connect the model’s linear score to an intuitive probability:

Quantity Conversion
Probability to odds p / (1 − p)
Odds to probability odds / (1 + odds)
Probability to log-odds log[p / (1 − p)]
Log-odds to probability 1 / (1 + e⁻ᶻ)

For example, if p = 0.8, the odds are 0.8 / 0.2 = 4, and the log-odds are log(4) ≈ 1.386. A probability of 0.8 means the event is estimated to be four times as likely as its alternative—not that it is four times more probable in every possible sense.

Calculate a binary prediction by hand

Suppose a subscription-renewal model uses usage hours and a satisfaction indicator:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

z = −2 + 0.8 × usage hours + 1.2 × satisfaction score

For a customer with 2 usage hours and satisfaction score 1:

  1. Calculate the score: z = −2 + 0.8 × 2 + 1.2 × 1 = 0.8.

  2. Apply the sigmoid: p = 1 / (1 + e⁻⁰·⁸) ≈ 0.69.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Interpret the output as an estimated renewal probability of about 69%.

At a probability threshold of 0.5, this example is classified as “renew.” At a threshold of 0.8, it is not. The threshold changes the classification decision, not the fitted probability model. A 0.5 cutoff is common, but it is not mandatory; the appropriate threshold depends on the relative costs of false positives and false negatives or other operational requirements.

How to interpret logistic-regression coefficients

A coefficient describes how a feature changes the log-odds when other included features are held fixed. Exponentiating a coefficient gives the corresponding odds multiplier:

odds multiplier = eᵝʲ

If βⱼ = 0.7, then e⁰·⁷ ≈ 2.01: a one-unit increase in that feature multiplies the modeled odds by about 2.01, with other features fixed. This is not a doubling of probability. The probability change depends on the starting probability.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What entropy means in maximum-entropy modeling

For a discrete probability distribution, entropy is:

H(P) = −Σᵧ P(y) log P(y)

Entropy measures uncertainty or spread. A fair binary outcome with probabilities 0.5 and 0.5 has more entropy than an outcome with probabilities 0.99 and 0.01. But maximum-entropy modeling does not mean ignoring the data or making every class equally likely. It means choosing the distribution with the greatest entropy among those that satisfy the information constraints we specify—in other words, making no additional assumptions beyond those constraints.

How feature constraints produce a maximum-entropy classifier

Let fⱼ(x, y) be a feature function that measures something about an input and a candidate label. A constraint can require the model’s expected value for that feature to match the empirical value observed in the training data:

Σₓ,ᵧ P(x, y) fⱼ(x, y) = observed feature expectation

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Maximum-entropy modeling chooses the distribution that maximizes H(P) while respecting the constraints, valid probabilities, and normalization. Using Lagrange multipliers to solve that constrained optimization yields an exponential-family form:

P(y | x) = exp(Σⱼ λⱼ fⱼ(x, y)) / Z(x)

Here, Z(x) = Σᵧ′ exp(Σⱼ λⱼ fⱼ(x, y′)) is a normalizing term that makes the probabilities for all possible labels add to one. The feature weights λⱼ determine how much each feature contributes to the score. The classic treatment by Berger, Della Pietra, and Della Pietra derives this exponential form and explains its connection to maximum likelihood in “A Maximum Entropy Approach”.

A text-classification example

Imagine classifying email as spam or not spam, using features that indicate whether the words “free” and “winner” appear. Feature functions can pair the presence of each word with a candidate label. When a feature associated with spam is present, its learned weight adds to the spam score. The model exponentiates the scores and normalizes them into probabilities. An email containing neither word can still receive a prediction based on the model’s learned baseline and any other features included.

Scores are additive before exponentiation, which is why these models are also called log-linear. Feature choice matters: the model only uses relationships represented by its feature functions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why binary logistic regression is a maximum-entropy model

For two labels, 0 and 1, use features that activate when a particular input feature is present and the candidate label is 1. Include an intercept as a feature as well. The conditional exponential-family form becomes:

P(y = 1 | x) = exp(β₀ + βᵀx) / [1 + exp(β₀ + βᵀx)]

Dividing numerator and denominator by the exponential term in the denominator gives:

P(y = 1 | x) = 1 / [1 + exp(−(β₀ + βᵀx))]

That is exactly the logistic-regression sigmoid. The equivalence is between logistic regression and conditional maximum-entropy classification: both model P(y | x). It does not mean that logistic regression is equivalent to every model called maximum entropy. Maximum-entropy methods can model joint distributions, sequences, or other structured outcomes too.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In the unregularized case, with matching feature representation and constraints, the maximum-likelihood and conditional maximum-entropy formulations yield the same exponential-family model. The precise relationship and its conditions are discussed in the original maximum-entropy treatment.

How maximum likelihood becomes cross-entropy loss

Given training observations (xᵢ, yᵢ), maximum likelihood chooses parameters that make the observed labels probable. For binary labels, the likelihood is the product of the probabilities assigned to each observed outcome. Taking its logarithm turns that product into a sum:

ℓ(β) = Σᵢ [yᵢ log(pᵢ) + (1 − yᵢ) log(1 − pᵢ)]

Training maximizes this log-likelihood, or equivalently minimizes its negative, called binary cross-entropy or log loss:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

−ℓ(β) = −Σᵢ [yᵢ log(pᵢ) + (1 − yᵢ) log(1 − pᵢ)]

A confident correct probability is rewarded, while a confident wrong one is penalized heavily. That is why accuracy alone cannot tell you whether a model’s probabilities are useful. Two models can predict the same class labels but assign very different probabilities.

Multiclass logistic regression and softmax

For K classes, multinomial logistic regression assigns a score βₖᵀx to each class and converts all scores into probabilities with softmax:

P(y = k | x) = exp(βₖᵀx) / Σⱼ exp(βⱼᵀx)

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Because every class shares the denominator, the probabilities sum to one. For scores 1, 0, and −1, exponentiating gives approximately 2.718, 1, and 0.368. Dividing by their total, about 4.086, gives:

Class score Softmax probability
1 Refund: approximately 0.665
0 Complaint: approximately 0.245
−1 Praise: approximately 0.090

For numerical stability, implementations often subtract the largest score from every score before exponentiating; because the same amount is subtracted from all scores, the probabilities do not change.

Multinomial versus one-vs-rest

These are different model strategies and can produce different probabilities and decision boundaries. The scikit-learn LogisticRegression reference documents solver support: liblinear is limited to binary classification unless wrapped in a one-vs-rest strategy, while the other listed solvers support multinomial loss for multiclass problems.

Regularization and the practical model

Training data can be fit too closely, particularly when there are many features or correlated predictors. Regularization adds a penalty on coefficient size to the negative log-likelihood. Common forms include:

Penalty Typical effect
L2: λ||β||₂² Shrinks coefficients smoothly; often useful when many features contribute.
L1: λ||β||₁ Can set some coefficients exactly to zero, producing a sparser model.
Elastic net Combines L1 and L2 effects.

Regularization can reduce overfitting and improve numerical stability, but it changes the fitted objective. It is therefore not the same as the unregularized maximum-likelihood derivation of the basic maximum-entropy equivalence. In scikit-learn, C is the inverse of regularization strength: a smaller value means stronger regularization. Supported penalties depend on solver. These implementation details can change between versions, so consult the API reference for the installed version.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fit and evaluate logistic regression in Python

This example uses scikit-learn’s Iris dataset to fit a regularized multiclass model. Scaling and model fitting are kept in a pipeline, so the scaler is learned from the training data rather than the full dataset.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import (
    accuracy_score,
    classification_report,
    confusion_matrix,
    log_loss,
)
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

X, y = load_iris(return_X_y=True)

X_train, X_test, y_train, y_test = train_test_split(
    X,
    y,
    test_size=0.25,
    random_state=42,
    stratify=y,
)

model = make_pipeline(
    StandardScaler(),
    LogisticRegression(max_iter=1000, solver="lbfgs"),
)

model.fit(X_train, y_train)
predicted_labels = model.predict(X_test)
predicted_probabilities = model.predict_proba(X_test)

print("Accuracy:", accuracy_score(y_test, predicted_labels))
print("Log loss:", log_loss(y_test, predicted_probabilities))
print(confusion_matrix(y_test, predicted_labels))
print(classification_report(y_test, predicted_labels))
  1. load_iris provides a dataset with multiple classes.

  2. train_test_split reserves data for evaluation; stratify=y helps preserve class proportions in both partitions.

  3. StandardScaler puts numeric features on comparable scales. Scaling is especially important for some optimization solvers; scikit-learn notes that sag and saga converge reliably when features have approximately similar scales.

  4. fit learns model parameters from the training data. predict returns labels, while predict_proba returns class probabilities.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  5. Accuracy measures the share of correct labels; log loss assesses the probabilities assigned to the true labels. The confusion matrix and classification report show class-specific errors and metrics.

The code avoids version-sensitive options not needed for this example. Scikit-learn’s documented defaults and parameter options can change, so check the current reference for the version you use.

Common failure modes and how to address them

Perfect separation

Separation occurs when a feature or combination of features perfectly divides the training classes—for example, every observation above an income cutoff belongs to one class and every observation below it belongs to the other. Unregularized maximum-likelihood coefficients can grow without bound; optimization may fail to converge, and estimates can become unreliable. Regularization can give finite estimates, but those estimates then depend on the penalty.

Class imbalance

When one class is much more common, a high accuracy score can hide poor performance on the less common class. Examine precision, recall, F1, a confusion matrix, and—when relevant—ROC-AUC or precision-recall AUC. Class weighting changes the optimization target and may also affect how probabilities should be interpreted; it is not a cost-free correction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Poor probability calibration

A model can rank cases usefully while its probabilities do not match observed frequencies. If decisions depend on probability values, assess calibration with a reliability diagram or calibration curve, along with metrics such as log loss or the Brier score. Scikit-learn documents sigmoid and isotonic calibration approaches and their use of held-out data or cross-validation in its calibration guide.

Data leakage

Do not fit preprocessing, select features, or oversample using information from the test set or from validation folds that should be held out. Avoid variables recorded after the outcome. Keep preprocessing inside a pipeline so each training fold learns its own transformations.

Nonlinearity and missing interactions

A linear logistic model assumes a linear relationship between the features and log-odds. It will not automatically discover that one feature’s effect depends on another, or that an effect curves. Add justified interaction terms, polynomial features, or splines, or consider a generalized additive model or a tree-based method. More flexibility can capture structure but may make interpretation and validation more demanding.

When logistic regression is a good fit—and when it is not

It is often a strong starting point when the outcome is categorical, a roughly linear boundary is plausible, probability estimates or interpretability matter, and the data are small or medium-sized. It is also widely used for sparse features such as bag-of-words text, one-hot encoded categories, and as a fast baseline.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Consider another approach if the task has strongly nonlinear relationships, complex image or audio inputs, dependent observations, ordered outcomes that should use their ordering, or an extremely large number of classes. Depending on the problem, alternatives include random forests or gradient-boosted trees, generalized additive models, Naive Bayes, linear support-vector machines, neural networks, ordinal logistic regression, or mixed-effects models. A model choice should follow the data structure and evaluation needs, not the maximum-entropy label alone.

Quick Recap

Bestseller No. 1
Design of Experiments: Statistical Principles of Research Design and Analysis
Design of Experiments: Statistical Principles of Research Design and Analysis
New; Mint Condition; Dispatch same day for order received before 12 noon; Guaranteed packaging
$8.98
Bestseller No. 3
SaleBestseller No. 5

Logistic regression and maximum entropy compared

Question Logistic-regression view Conditional maximum-entropy view
What is modeled? P(y | x) P(y | x)
Central idea Choose parameters to maximize likelihood Choose the highest-entropy distribution that satisfies feature constraints
Form Sigmoid for binary; softmax for multinomial Conditional exponential family, normalized over labels
Training objective Negative log-likelihood, or cross-entropy Equivalent likelihood objective under matching features and constraints
Practical qualification Regularization and solver choices affect fitting Feature functions and constraints define the model

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.