ThisCalculator

Everyday

Logistic Regression Calculator: Formula and Example

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

Logistic Regression Calculator: Formula and Example

A logistic regression calculator estimates the probability of a binary outcome from one or more predictor values, using a fitted model’s coefficients. Enter the intercept, coefficients, and predictor values to get the predicted probability, odds, and classification at a chosen threshold; the calculator cannot fit a model from raw data by itself.

Formula

For a model with one predictor, the calculator first finds the linear predictor, often called the logit:

z = b₀ + b₁x₁

It then converts that value to a probability with the logistic function:

p = 1 / (1 + e−z)

  • b₀ is the intercept, a coefficient with no measurement unit.
  • b₁ is the predictor coefficient. Its unit is the inverse of the predictor’s unit, so that b₁x₁ is dimensionless.
  • x₁ is the predictor value, in the same units used when fitting the model.
  • z is the logit, or log-odds, and is dimensionless.
  • p is the predicted probability, from 0 to 1. Multiply it by 100 to express it as a percentage.

The predicted odds are p / (1 − p). To turn probability into a binary prediction, compare it with a threshold c: predict class 1 when p is at least c, and class 0 otherwise. The calculator’s class expression returns 1 when p is at least c and 0 when it is below c, for a threshold between 0 and 1.

Worked Example

Using the block’s default values, the intercept is 0, the coefficient is 1, the predictor value is 0, and the threshold is 0.5.

  1. Calculate the logit: z = 0 + (1 × 0) = 0.
  2. Convert it to probability: p = 1 / (1 + e0) = 1 / 2 = 0.5000, or 50.00%.
  3. Calculate odds: 0.5 / (1 − 0.5) = 1.0000, or 1 to 1.
  4. Compare probability with the threshold: 0.5 is at least 0.5, so the predicted class is 1.

These outputs describe the mathematical result for the supplied coefficients. The defaults are an illustration, not a model trained on real observations.

What a Logistic Regression Calculator Does

Logistic regression is a statistical method for modeling outcomes with two possible categories, such as an event occurring or not occurring. Despite the word “regression,” its commonly used output is a probability rather than a continuous measurement. A model estimates how the predictors relate to the log-odds of the event, then transforms those log-odds into a probability between 0 and 1.

A calculator like this evaluates an existing equation. To obtain meaningful coefficients, a model must first be fitted to labeled data using statistical software or another suitable method. The coefficients depend on that data, the outcome definition, predictor coding, and model specification. A calculator cannot infer them from an outcome label or a single person’s predictor values.

Using More Than One Predictor

With multiple predictors, the same method applies, but the linear predictor includes every coefficient-value product:

z = b₀ + b₁x₁ + b₂x₂ + … + bₖxₖ

Each predictor can represent a measured quantity or a coded category. For a categorical predictor, the model may use indicator variables; the coefficient then represents a contrast against the chosen reference category, not a direct effect per unit of a natural measurement. A multi-predictor calculator needs an input for every coefficient and its corresponding predictor value. The one-predictor block above is a compact example, not a substitute for adding terms that belong in a real model.

Keep the model’s original coding and units. If a model was fitted with age in years, entering age in months changes the product b₁x₁ by a factor of 12. If variables were standardized or transformed during fitting, apply the same transformation before calculating a prediction.

How to Interpret Probability, Odds, and Class

A predicted probability of 0.72 means the model assigns a 72% probability to the modeled event for that predictor pattern. It is not a guarantee that the event will occur, nor does one prediction establish that the model is well calibrated. Calibration asks whether, across many cases assigned similar probabilities, the observed event frequency is close to those probabilities.

Odds are not the same as probability. A probability of 0.8 corresponds to odds of 4 to 1, since 0.8 / 0.2 = 4. A probability of 0.5 corresponds to even odds. Coefficients are expressed in log-odds: increasing a predictor by one unit changes the log-odds by its coefficient, holding other predictors fixed. Exponentiating a coefficient gives the associated odds multiplier, but it does not directly give a probability increase that is identical for every case.

The threshold turns a probability into a class label. The conventional 0.5 cutoff is not automatically the best choice. Raising or lowering it changes which cases are labeled positive, affecting measures such as sensitivity and specificity. Threshold selection should reflect the task and the consequences of false positives and false negatives; probability estimation and classification are separate decisions.

Common Mistakes and Model Limits

  • Using coefficients from a different model: coefficients only make sense with the outcome coding, predictors, transformations, and units used to estimate them.
  • Confusing odds with probability: odds can exceed 1, while probability stays between 0 and 1.
  • Rounding too early: calculate with the full coefficient precision, then round the displayed result. Small rounding changes near the classification threshold can change a class label.
  • Assuming association proves causation: a predictive relationship alone does not show that changing a predictor causes the outcome to change.
  • Trusting a prediction outside the data range: extrapolating far beyond the values represented in training data can produce numbers that look precise but are unreliable.

Logistic regression also depends on appropriate model assumptions and data quality. Important considerations include how observations were sampled, whether relevant predictors or interactions are missing, whether predictors are strongly related to one another, and whether the model performs well on data not used to fit it. A calculated probability is only as useful as the model behind it.

Frequently Asked Questions

Can I use a logistic regression calculator without coefficients?
No. The coefficients must come from a fitted model. This calculator evaluates an equation; it does not estimate coefficients from raw observations.

Does a logistic regression calculator give a percentage?
It returns probability as a decimal between 0 and 1. Multiply by 100 to express it as a percentage; for example, 0.37 is 37%.

Why can a coefficient be negative?
A negative coefficient means that, holding other model terms fixed, a one-unit increase in that predictor lowers the modeled log-odds of the event. Its effect on probability depends on the starting values of the predictors.

Is 0.5 always the correct classification threshold?
No. It is a common default, not a universal rule. The appropriate cutoff depends on the goal, the costs of different errors, and how the model performs on relevant data.

Can logistic regression handle multiple predictors?
Yes. Its linear predictor can include many terms. Calculate each coefficient times its matching predictor value, add them to the intercept, and apply the logistic function to the resulting total.

Related

Formula used
in b0 | Intercept | - | 0 | 
in b1 | Predictor coefficient | - | 1 | 
in x1 | Predictor value | - | 0 | 
in c | Classification threshold | - | 0.5 | 0
out p | Predicted probability | - | 1 / (1 + exp(-(b0 + b1 * x1))) | 4
out odds | Predicted odds | - | p / (1 - p) | 4
out class | Predicted class (0 or 1) | - | floor(p / c) | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.